将 unicode 代码点转换为 Ruby 中的字符串字符 [英] Convert unicode codepoint to string character in Ruby
本文介绍了将 unicode 代码点转换为 Ruby 中的字符串字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有来自 unicode 数据库的这些值,但我不确定如何将它们转换为人类可读的形式.这些甚至叫什么?
I have these values from a unicode database but I'm not sure how to translate them into the human readable form. What are these even called?
他们在这里:
U+2B71F
U+2A52D
U+2A68F
U+2A690
U+2B72F
U+2B4F7
U+2B72B
如何将这些转换为可读符号?
How can I convert these to there readable symbols?
推荐答案
怎么样:
# Using pack
puts ["2B71F".hex].pack("U")
# Using chr
puts (0x2B71F).chr(Encoding::UTF_8)
在 Ruby 1.9+ 中你也可以这样做:
In Ruby 1.9+ you can also do:
puts "u{2B71F}"
即u{}
转义序列可用于解码 Unicode 代码点.
I.e. the u{}
escape sequence can be used to decode Unicode codepoints.
这篇关于将 unicode 代码点转换为 Ruby 中的字符串字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文