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 = "\s")

Arguments

x

string or vector of strings to trim

what

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

side

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

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.6.2 Index]