$linkNumber = [“十”,“百”,“千”,“万”,“億”]
p $linkNumber[0].
when i run above codes
Result is: “\u5341”
but i want “十”
how to fix it, please teach me!
$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.
try:
puts $linkNumber[0]
or:
print $linkNumber[0]
Not sure if the period in p $linkNumber[0].
is intentional or not.
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
"十"
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