Ruby 将十六进制转换为字符并打印(Unicode 希伯来语)
您好,我正在开展一个需要分析希伯来字符的项目。
我有这样的情况,所以
letter = case
when (a[0] == "1") && (a[1] == "2"): "He ה"
...
end
p letter
=> "He ה"
我还想从 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。 $KCODE = "u" 在代码上方设置。
我需要做什么?我尝试了一些不同的方法但无济于事(例如, ['05D5'.hex].pack("C") )=>错误字符超出范围
提前致谢。
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 ה"
...
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
唯一的问题是你的调试代码。
Kernel#p
写入 object.inspect
,这可能有点难以向您展示内部结构。只要使用像 puts 这样的真正的 I/O 方法,我想你会没事的。
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.