[英]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: 我还想从Unicode十六进制数字(对于He 05D4)打印希伯来字符,如下所示:
letter = case
when (a[0] == "1") && (a[1] == "2"): "\05D4 He ה"
...
end
p letter
Desired output => "ה He ה"
Actual output => "\005D4 He ה"
Ruby 1.8.8. Ruby 1.8.8。 $KCODE = "u" is set above code.
$ KCODE =“ u”在上面的代码中设置。
What do I need to do? 我需要做什么? I have tried a few different things to no avail (eg, ['05D5'.hex].pack("C") ) => error char out of range
我尝试了一些不同的尝试,但无济于事(例如['05D5'.hex] .pack(“ C”))=>错误字符超出范围
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. Kernel#p
编写了对象 .inspect
,并且它尝试显示您的内部结构可能太难了。
Just use a real I/O method like puts
and I think you will be fine. 只需使用
puts
等真正的I / O方法,我认为您会好的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.