我的泰国字符串是: “หลับตาฝันถึงชื่อเธอ”Ruby:如何转码utf-8字符串?
,我需要输出的UTF-8编码是这样的: “\ u0e08 \ u0e2d \ u0e21 \ u0e40 \ u0e27 \ u0e17 \ u0e22 \ u0e4c \ u0e21 \ u0e2b \ u0e32"
此刻,我安装了 '的iconv' 宝石和正在使用
string = Iconv.conv('unicode', 'utf-8', string)
但它不工作。
invalid encoding ("unicode", "utf-8") (Iconv::InvalidEncoding)
我需要使用Iconv还是编码? (我在Ruby 2.3.1上)
在IRB(在我的代码) ' “หลับตาฝันถึงชื่อเธอ” .encode( “UTF-8”)' 只要输出 ' “หลับตาฝันถึงชื่อเธอ”' – matski
由于@peter 好像IRB甚至没有认识到的unicode: ' “หลับตาฝันถึงชื่อเธอ” .encoding =>#<编码:UTF-8> “\ u0E2B \ u0E25 \” 编码 =>#<编码:。UTF -8>' – matski
甚至不能在irb中显示thai字符,必须是关于代码页的东西(我在windows上),测试它像我这样的脚本编辑 – peter