strip: Remove Leading and Trailing White Spaces

stripR Documentation

Remove Leading and Trailing White Spaces

Description

strip removes leading and trailing white space from each element of a character vector. White space characters include tab, newline, vertical tab, form feed, carriage return, space and possible other locale-dependent characters.

Usage

strip(x)

Arguments

x

a character vector, or an object which can be coerced by as.character to a character vector. Long vectors are supported.

Value

strip returns a character vector of the same length and with the same attributes as x (after possible coercion to character). Elements of character vectors x which are not substituted will be returned unchanged (including any declared encoding).

Examples

x <- c(
    "  the quick brown fox jumps over a lazy dog  ",
    "  the quick brown fox jumps over a lazy dog\t\n"
)
strip(x)  # the leading and trailing tab, newline, and space are removed


## x is intended to be in encoding latin1
x <- "fa\xE7ile"
Encoding(x) <- "latin1"
y <- strip(x)


## since 'x' has no leading or trailing white space, 'strip(x)' retains the
## encoding of 'x'
Encoding(y)
y

ArcadeAntics/essentials documentation built on Nov. 7, 2024, 4:33 p.m.