str_trim()
removes whitespace from start and end of string; str_squish()
removes whitespace at the start and end, and replaces all internal whitespace
with a single space.
str_trim(string, side = c("both", "left", "right"))
str_squish(string)
A character vector the same length as string
.
str_pad()
to add whitespace
str_trim(" String with trailing and leading white space\t")
#> [1] "String with trailing and leading white space"
str_trim("\n\nString with trailing and leading white space\n\n")
#> [1] "String with trailing and leading white space"
str_squish(" String with trailing, middle, and leading white space\t")
#> [1] "String with trailing, middle, and leading white space"
str_squish("\n\nString with excess, trailing and leading white space\n\n")
#> [1] "String with excess, trailing and leading white space"