Skip to contents

Get the length in characters or width of strings, which differ where some characters take up multiple characters worth of space, like emojis.

Usage

str_length(strings)

str_width(strings)

Arguments

strings

A character vector, where each element of the vector is a character string.

Value

A numeric vector the same length as string.

str_length(): The number of characters in a string.

str_width(): The amount of space the string will take up when printed with a fixed-width font, such as in the console.

See also

Base nchar() which these functions are built with.

Examples

str_length(c("Hello", "everyone"))
#> [1] 5 8

str_length("😊")
#> [1] 1
str_width("😊")
#> [1] 2