Skip to content
Prev 11528 / 398502 Next

Trimming blanks from the ends of strings

s-luppescu at uchicago.edu wrote:
Something like

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

should do the trick.  E.g.

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