Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in R Programming by (7.3k points)

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.

And what about Unicode strings? How do I find the length (in bytes) and the number of characters (runes, symbols) in a Unicode string?

1 Answer

0 votes
by

To find the length of a string in R, you can use the nchar() function as follows:

nchar("String")

Output: 

[1] 6

To find the length of multiple strings and exclude NA’s, you can use the stri_length() function from the stringi package as follows:

stri_length(c("String","Count",NA))

Output:

[1]  6  5 NA

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...