str_trim: Remove whitespace

View source: R/trim.R

str_trimR Documentation

Remove whitespace

Description

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.

Usage

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

str_squish(string)

Arguments

string

Input vector. Either a character vector, or something coercible to one.

side

Side on which to remove whitespace: "left", "right", or "both", the default.

Value

A character vector the same length as string.

See Also

str_pad() to add whitespace

Examples

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")

stringr documentation built on Nov. 15, 2023, 1:08 a.m.