Technically this returns the number of "code points", in a string. One code point usually corresponds to one character, but not always. For example, an u with a umlaut might be represented as a single character or as the combination a u and an umlaut.
str_length(string)
string | Input vector. Either a character vector, or something coercible to one. |
---|
A numeric vector giving number of characters (code points) in each element of the character vector. Missing string have missing length.
stringi::stri_length()
which this function wraps.
str_length(letters)#> [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1str_length(NA)#> [1] NA#> [1] 3#> [1] 1 4 11 NA# Two ways of representing a u with an umlaut u1 <- "\u00fc" u2 <- stringi::stri_trans_nfd(u1) # The print the same: u1#> [1] "ü"u2#> [1] "ü"# But have a different length str_length(u1)#> [1] 1str_length(u2)#> [1] 2#> [1] 1str_count(u2)#> [1] 1