如何在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