string.tr bug?

B

borasque

Greetings,
I found strange behaviour of string.tr:

p "=+=/=".tr("+/=", ",-@")
got ".,.-."
expected "@,@-@"

Is this bug in ruby?
 
S

Sebastian Hungerecker

I found strange behaviour of string.tr:

p "=+=/=".tr("+/=", ",-@")
got ".,.-."
expected "@,@-@"

Is this bug in ruby?

It's not a bug. For tr ",-@" is the same as ",-./0123456789:;<=>?@". You have
to escape the - to use it as a literal "-":
"=+=/=".tr("+/=", ',\-@') #=> "@,@-@"

HTH,
Sebastian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top