trim {utilitiesR}R Documentation

trim white spaces from a string

Description

This trims all white spaces from specified sides of a string.

Usage

  trim(x, side = c("both", "left", "right"),
    what = "[[:space:]]", perl = FALSE)

Arguments

x

string or vector of strings to trim

what

what to trim (interpreted as regex): \s or [[:space:]] is all white space, could use ' ' for just plain spaces.

side

One of 'both','left','right': which side(s) to trim.

perl

boolean, whether the what regex is perl or not.

Value

x trimmed.

Examples

x <- '   a   '
trim(x,side='left')  # 'a   '
trim(x,side='right') # '   a'
trim(x)              # 'a'

y <- 'One line\nTwo lines\n\n  '
trim(y)              # 'One line\nTwo lines'
trim(y,what=' ')     # 'One line\nTwo lines\n\n' (trimmed just space)

[Package utilitiesR version 1.8.2 Index]