gpt4 book ai didi

ruby - 使用 ruby​​ 将 unicode 转换为字符

转载 作者:数据小太阳 更新时间:2023-10-29 06:47:44 25 4
gpt4 key购买 nike

我找到了一本unicode汉字字典。我正在尝试从这本词典中构建一个字符数据库,但我不知道如何将 unicode 转换为字符..

p "国".unpack("U*").first #this gives the unicode 22269

如何将 22269 转换回与上述行相反的字符值。

最佳答案

ruby 1.9:

p "国".codepoints.first #=> 22269
p 22269.chr('UTF-8') #=> "国"

关于ruby - 使用 ruby​​ 将 unicode 转换为字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4620549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com