在Ruby中将Unicode代码点转换为字符串字符 [英] Convert unicode codepoint to string character in Ruby
本文介绍了在Ruby中将Unicode代码点转换为字符串字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从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
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.
这篇关于在Ruby中将Unicode代码点转换为字符串字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文