Skip to contents

Shorten a string to a specified size

Usage

str_truncate(
  strings,
  length,
  side = c("right", "left", "center"),
  ellipsis = "..."
)

Arguments

strings

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

length

The maximum number of characters per string in the output vector.

side

Where the truncation should happen i.e. the location to remove characters from.

ellipsis

Characters to replace removed characters, indicating shortening, an ellipsis "..." by default

Value

A character vector equal in length() to strings, with each element equal or more characters than length shortened to that many characters.

See also

str_pad() for padding a string to a certain length.

Examples

str_truncate("Help me make this shorter", 15)
#> [1] "Help me make..."
str_truncate("Help me make this shorter", 15, "left")
#> [1] "...this shorter"
str_truncate("Help me make this shorter", 15, "center")
#> [1] "Help m...horter"