I'm trying to work with unicode characters, and the information provided by the string's .ord method doesn't help me. I'm used to working with codes like "\uXXXX".
ruby-1.9.3-p0 :119 > form[0]
=> "כ"
ruby-1.9.3-p0 :120 > form[0].ord
=> 1499
ruby-1.9.3-p0 :121 > puts "\u1499"
ᒙ
...
:-(
The values yielded by .ord seem to correspond to the 'decimal points' referred to here: http://www.i18nguy.com/unicode/hebrew.html
I don't know how to work with these values. How do I get the \uXXXX code from that character?
Thank you
The \u
syntax uses hexadecimal, you're giving it a decimal value. You want:
>> "%4.4x" % form[o].ord
"05db"
>> puts "\u05db"
כ
mu is too short's answer is cool.
But, the simplest answer is:
'好'.ord.to_s(16) # => '597d'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With