Greetings,
I found strange behaviour of string.tr:
p “=+=/=”.tr("+/=", “,-@”)
got “.,.-.”
expected “@,@-@”
Is this bug in ruby?
Greetings,
I found strange behaviour of string.tr:
p “=+=/=”.tr("+/=", “,-@”)
got “.,.-.”
expected “@,@-@”
Is this bug in ruby?
[email protected] wrote:
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs