从十六进制字符串表示形式中创建RAW UNICODE字符

发布于 2025-01-20 04:15:20 字数 399 浏览 1 评论 0原文

给定一个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

Given the string hex representation of a Unicode character, I would like to print the Unicode character it represents

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

Instead, I want it to print "A A"

Use Case:
For a demo, I would like to loop over a range of values and print a map from the hex representation to the Unicode:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

套路撩心 2025-01-27 04:15:20

您可以这样做:

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

You can just do:

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)

For other cases consider using the forementioned unescape_string

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文