MonkeeSage
11/28/2007 5:07:00 PM
On Nov 28, 8:38 am, woodyee <wood_ye...@hotmail.com> wrote:
> Hi! I had to manually remove decimals and tildes from a text file. How
> could I have done this via programming? I googled this but didn't
> really find anything, just stuff on removing spaces. Basically, I'd
> like to be able to search a file and remove certain items (ex - all
> decimals and tildes). Thanks!
How about...
"he~~ll.o".tr('~.', '') # => "hello"
String#tr translates a group of characters into another group, such
that for every character in a given position in group one, it is
replaced by the character in the same position in group two, or if
group two is shorter, it uses the last character in group two. In this
case, group two is empty, so everything in group one is replaced with
empty strings (i.e., deleted).
HTH,
Jordan