Unicode to String

$linkNumber = [“十”,“百”,“千”,“万”,“億”]
p $linkNumber[0].

when i run above codes
Result is: “\u5341”
but i want “十”

how to fix it, please teach me!

There is some variation in how environments respond to unicode.


puts $linkNumber[0]


print $linkNumber[0]

Not sure if the period in p $linkNumber[0]. is intentional or not.

1 Like

This happens (“\u5341”) when you have LANG environment variable set to non-unicode. I am not sure on other OS but on Linux:

Actually p runs the inspect method on the $linkNumber[0], which prints this character, and this is the default behaviour of p. You can use puts, print, printf, STDOUT.write, etc. to get around this. For example:

$linkNumber = ["十","百","千","万","億"]
puts %Q("#{$linkNumber[0]}")
> LANG=C ruby p.rb 
1 Like