From: Robert Klemme Date: 2005-03-21T21:04:50+09:00 Subject: Re: string.tr and \ "Tom Counsell" schrieb im Newsbeitrag news:193f68dcbb7799e1110cab8eb7a02248@cam.ac.uk... > Hello > > I'm a little confused and would appreciate your help. I would like to > remove any \ characters from a string as well as some other characters. > > 'b\\c['.tr('\\','') # => 'bc', which is great. > > 'b\\c'.tr('\\c','.') # => 'b\\' which is not great. > > Why does adding extra characters to the tr function stop the removal of > \ characters? Note also >> 'b\\c'.tr('c\\','.') => "b.." You're abusing String#tr - this method is intended to replace single chars by other single chars. That you can remove characters is a special case with empty replacement strings. You really should be using gsub or gsub!: >> 'b\\c'.gsub /\\/, '' => "bc" Kind regards robert