Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道是否有办法获取给定 UTF-8 代码的字符?
例如:
1103 = > "я"(russian letter)
使用Array#packwithU指令(UTF-8 字符):
Array#pack
U
[1103].pack('U') # => "я"
另一种方法是"\u{hex}",例如"\u{4355}"。此语法仅接受十六进制数字,而不接受十进制数字。语法 U+184B 是引用 Unicode 字符最常用的一种。
"\u{hex}"
"\u{4355}"