From: Chad Perrin Date: 2008-02-06T07:58:10+09:00 Subject: Re: ruby wish-list On Wed, Feb 06, 2008 at 05:30:06AM +0900, Siep Korteling wrote: > Roger Pack wrote: > > Is it possible to easily strip arbitrary characters off a string? > > a la "abc:".strip ':' > > ? > > it looks like it's possible with gsub > > abc:'.gsub(/:$/, '') > > however the wish is a simpler function for it. > > > > If not then it goes on the wish list. > > > > Thanks. Sorry to ramble on. > > -Roger > > "abc:".chomp(":") > or > "abc:".chomp!(":") Note: That only works if the character you want to strip away is the last character in the string. When you don't supply an argument, it removes only any newline character at the end of the string, e.g.: > irb irb(main):001:0> foo = 'abc irb(main):002:0' ' => "abc\n" irb(main):003:0> foo => "abc\n" irb(main):004:0> foo.chomp => "abc" irb(main):005:0> -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] They always say that when life gives you lemons you should make lemonade. I always wonder -- isn't the lemonade going to suck if life doesn't give you any sugar?