Robert Klemme
8/8/2008 1:21:00 PM
2008/8/8 Martin DeMello <martindemello@gmail.com>:
> On Thu, Aug 7, 2008 at 5:03 PM, Junkone <junkone1@gmail.com> wrote:
>> strip function removes the trailing whitespace. i want to remove
>> trailing comma's. is there a additional parameter for strip or some
>> other function to do the same.
>
> string.gsub(/^,+/, '').gsub(/,+$/, '')
This can be done with a single gsub:
irb(main):001:0> s=",,a,,"
=> ",,a,,"
irb(main):002:0> s.gsub %r{^,+|,+$}, ''
=> "a"
However, both strip trailing and leading commas. So for trailing
commas this should be sufficient
irb(main):003:0> s.gsub %r{,+$}, ''
=> ",,a"
OP: And of course, use gsub! for inplace modification if you want that.
Kind regards
robert
--
use.inject do |as, often| as.you_can - without end