From: Robert Klemme Date: 2006-12-28T20:30:06+09:00 Subject: Re: Strip is not stripping trailing whitespace On 28.12.2006 09:56, William James wrote: > Taylor Strait wrote: >>> It couldn't have. >>> >>> strip removes newlines, because they are whitespace. >>> On the other hand, neither chomp nor strip removes "\240". >>> >>>>> "foo \n".strip >>> => "foo" >>>>> ("foo " + 0240.chr).chomp >>> => "foo \240" >> This is why I shouldn't code at 3:30am! I had used chop instead, which >> of course truncated the text in rare cases. How can I remove \240? >> >> -- >> Posted via http://www.ruby-forum.com/. > > Remove ASCII 128-- 255 at end of line: > > irb(main):016:0> "foo\240\250 \n".strip. > irb(main):017:0* sub(/[#{128.chr}-#{255.chr}]+$/,"") > => "foo" Why not combine them like this: irb(main):007:0> s="foo\240\250 \n" => "foo\240\250 \n" irb(main):015:0> s.sub /[\200-\377\s]+$/, '' => "foo" Cheers robert