Skip to contents

Remove trailing and leading whitespace

Usage

str_trim(strings)

str_squish(strings)

Arguments

strings

A character vector, where each element of the vector is a character string.

Value

The same character vector, but with whitespace removed from the start and end of each string.

Examples

print(str_trim("    Remove these extra spaces    "))
#> [1] "Remove these extra spaces"
print(str_trim("Remove trailing new line character \n"))
#> [1] "Remove trailing new line character"
print(str_trim("But leave space     in   the      middle"))
#> [1] "But leave space     in   the      middle"

print(str_squish(" Don't leave   space    in  the   middle   here  "))
#> [1] "Don't leave space in the middle here"