如何在R中找到字符串的长度 [英] How to find the length of a string in R
本文介绍了如何在R中找到字符串的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不将其拆分为 R 的情况下找到字符串的长度(字符串中的字符数)?我知道如何找到列表的长度而不是字符串的长度.
How to find the length of a string (number of characters in a string) without splitting it in R? I know how to find the length of a list but not of a string.
Unicode 字符串呢?如何找到 Unicode 字符串中的长度(以字节为单位)和字符数(符文、符号)?
And what about Unicode strings? How do I find the length (in bytes) and the number of characters (runes, symbols) in a Unicode string?
相关问题:
推荐答案
参见 ?nchar
.例如:
> nchar("foo")
[1] 3
> set.seed(10)
> strn <- paste(sample(LETTERS, 10), collapse = "")
> strn
[1] "NHKPBEFTLY"
> nchar(strn)
[1] 10
这篇关于如何在R中找到字符串的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文