Skip to contents

Removes whitespace from the left and right sides of a string.

Usage

str_trim2(x, whitespace = "[ \t\r\n]")

Arguments

x

(character)
The character vector to remove left and right side whitespace.

whitespace

(string: "[ \t\r\n]")
The regular expression used to match whitespace.

Value

character vector

Details

NULL is returned as character(0L).

See also

Examples

#----------------------------------------------------------------------------
# str_trim2() examples
#----------------------------------------------------------------------------
library(bkbase)

x <- " example "
str_trim2(x)
#> [1] "example"

str_trim2(c(" a ", "\tb\n", NA))
#> [1] "a" "b" NA 
str_trim2("--x--", whitespace = "-")
#> [1] "x"