Ruby convert hexadecimal to character and print (Unicode Hebrew)
Hello I am working on a project that requires analysis of Hebrew characters.
I have a case like so
letter = case
when (a[0] == "1") && (a[1] == "2"): "He ה"
...
end
p letter
=> "He ה"
I want to also print the Hebrew character from Unicode hex number (for He 05D4), like so:
letter = case
when (a[0] == "1") && (a[1] == "2"): "\05D4 He ה"
开发者_如何学Go ...
end
p letter
Desired output => "ה He ה"
Actual output => "\005D4 He ה"
Ruby 1.8.8. $KCODE = "u" is set above code.
What do I need to do? I have tried a few different things to no avail (e.g., ['05D5'.hex].pack("C") ) => error char out of range
Thanks in advance.
The only problem is your debugging code. Kernel#p
writes object.inspect
, and that tries perhaps a bit too hard to show you internal structure.
Just use a real I/O method like puts
and I think you will be fine.
精彩评论