[R] Q about strsplit and regexp

Gabor Grothendieck ggrothendieck at myway.com
Thu Oct 21 07:55:43 CEST 2004


John Fox <jfox <at> mcmaster.ca> writes:

: This is something that I sometimes want to do, so I have a little utility
: that trims blanks and tabs from the beginnings and ends of strings:
: 
: trim.ws <- function(text) gsub("^[\ \t]", "", gsub("[\ \t]*$", "", text))
: 

This can be reduced to a single gsub like this:

  gsub("^[[:space:]]+|[[:space:]]+$", "", text)




More information about the R-help mailing list