Skip to content

Trimming blanks from the ends of strings

1 message · Ross Ihaka

#
s-luppescu at uchicago.edu wrote:
Something like

  sub("^  *", "", sub("  *$", "", x))

should do the trick.  E.g.

  > sub("^  *", "", sub("  *$", "", "  padded  "))
  [1] "padded"