trim {utilitiesR} | R Documentation |
This trims all white spaces from specified sides of a string.
trim(x, side = c("both", "left", "right"), what = "\s")
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. |
x trimmed.
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)