从十六进制字符串表示创建原始 unicode 字符

Create raw unicode character from hex string representation

给定 Unicode 字符的字符串十六进制表示,我想打印它所代表的 Unicode 字符

julia> s1, s2 = raw"\u0041", raw"\x41"
julia> println(s1,' ', s2)
\u0041 \x41

相反,我希望它打印“A A”

用例: 对于演示,我想遍历一系列值并打印从十六进制表示到 Unicode 的映射:

for ii = 0x0021 : 0x007f
    hex_rep = string(ii, base=16)
    unicode = raw"\u" * lpad(hex_rep, 4, '0')
    println(hex_rep, " -> ", unicode)
end

你可以这样做:

julia> Char.(0x0021 : 0x007f)
95-element Vector{Char}:
 '!': ASCII/Unicode U+0021 (category Po: Punctuation, other)
 '"': ASCII/Unicode U+0022 (category Po: Punctuation, other)
 '#': ASCII/Unicode U+0023 (category Po: Punctuation, other)
 ⋮
 '}': ASCII/Unicode U+007D (category Pe: Punctuation, close)
 '~': ASCII/Unicode U+007E (category Sm: Symbol, math)
 '\x7f': ASCII/Unicode U+007F (category Cc: Other, control)

对于其他情况考虑使用上述unescape_string