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

Forum statistics

Threads
474,183
Messages
2,570,969
Members
47,524
Latest member
ecomwebdesign

Latest Threads

Top