Skip to content
R

stringr API Reference

stringr — a tidyverse package providing a consistent, pipe-friendly API for string manipulation.

By EZ4Code Team

stringr functions

Consistent string manipulation functions from the stringr package, all prefixed with str_.

str_length(string) -> integer

Returns the number of characters (code points) in each string of a character vector.

Returns: integer

str_sub(string, start = 1L, end = -1L) -> character

Extracts substrings by position. Negative indices count from the end.

Returns: character

str_detect(string, pattern) -> logical

Returns TRUE for each string that matches the pattern, FALSE otherwise.

Returns: logical

str_replace(string, pattern, replacement) -> character

Replaces the first match of pattern in each string with replacement.

Returns: character

str_to_lower(string) -> character

Converts strings to lowercase using Unicode rules.

Returns: character

str_split(string, pattern) -> list

Splits each string by pattern, returning a list of character vectors.

Returns: list

str_c(..., sep = "") -> character

Concatenates strings element-wise. The stringr equivalent of paste0/paste.

Returns: character

str_trim(string, side = c("both", "left", "right")) -> character

Trims whitespace from the start, end, or both sides of each string.

Returns: character

More R API References