Skip to contents

Pattern matching

Manipulate strings based on regular expressions (or fixed literal strings).

Match patterns across the entire character vector

chr_which()
Find matching indices in character vector
chr_subset()
Get matching elements
chr_count_matches()
Count matching indices in character vector

Combining strings

str_concat()
Concatenate strings
str_glue()
Evaluate R code within strings
chr_collapse()
Collapse a character vector to a single string

Character-based transformation

Functions for cleaning and transforming strings with respect to characters.

str_length() str_width()
Get the length or width of strings

Shorten strings

str_trim() str_squish()
Remove trailing and leading whitespace
str_truncate()
Shorten a string to a specified size

Extend strings

str_repeat()
Repeat character sequences
str_pad()
Pad a string to a minimum length
str_indent()
Add characters to the ends of strings

Reformat strings

str_to_upper_case() str_to_lower_case() str_to_snake_case() str_to_camel_case()
Convert strings to different cases
str_wrap()
Wrap character strings to format as paragraphs

Organise character vectors

chr_sort() chr_order() chr_rank()
Re-organise a character vector
chr_unique()
Remove duplicated strings