str_trim: Trim whitespace from a string

Description Usage Arguments Value See Also Examples

Description

str_trim() removes whitespace from start and end of string; str_squish() also reduces repeated whitespace inside a string.

Usage

1
2
3
str_trim(string, side = c("both", "left", "right"))

str_squish(string)

Arguments

string

A character vector.

side

Side on which to remove whitespace (left, right or both).

Value

A character vector.

See Also

str_pad() to add whitespace

Examples

1
2
3
4
5
str_trim("  String with trailing and leading white space\t")
str_trim("\n\nString with trailing and leading white space\n\n")

str_squish("  String with trailing,  middle, and leading white space\t")
str_squish("\n\nString with excess,  trailing and leading white   space\n\n")

Example output

[1] "String with trailing and leading white space"
[1] "String with trailing and leading white space"
[1] "String with trailing, middle, and leading white space"
[1] "String with excess, trailing and leading white space"

stringr documentation built on May 2, 2019, 11:03 a.m.