[R] removing leading/trailing blanks

white.denis@epamail.epa.gov white.denis at epamail.epa.gov
Wed Feb 19 22:21:03 CET 2003


> Hi,
>
> What's the best way of dropping leading or trailing
> blanks from a character string?
>
> The only thing I can think of is using sub() to replace
> blanks with null strings, but I don't know if there is
> a better way (I also don't know how to represent the
> trailing blank in a regular expression).
>
> Thanks,
> Doug Grove

sub ("^[ \t]*", "", sub ("[ \t]*$", "", "  hello  "))




More information about the R-help mailing list