convert unicode into character with ruby

后端 未结 2 1904
梦毁少年i
梦毁少年i 2021-02-03 12:29

I found a dictionary of Chinese characters in unicode. I\'m trying to build a database of Characters out of this dictionary but I don\'t know how to convert unicode to a charact

2条回答
  •  故里飘歌
    2021-02-03 12:43

    [22269].pack('U*') #=> "国" or "\345\233\275"
    

    Edit: Works in 1.8.6+ (verified in 1.8.6, 1.8.7, and 1.9.2). In 1.8.x you get a three-byte string representing the single Unicode character, but using puts on that causes the correct Chinese character to appear in the terminal.

提交回复
热议问题