如何将UCS2字符串转换为UTF8? [英] How do I convert a UCS2 string into UTF8?
本文介绍了如何将UCS2字符串转换为UTF8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Ruby中将UCS2中的字符串(每个字符2个字节)转换为UTF8字符串?
How to convert a string that is in UCS2 (2 bytes per character) into a UTF8 string in Ruby?
推荐答案
您应该查看图标,它是Ruby标准库的一部分.它是为此任务而设计的.
You should look into iconv, which is part of the Ruby standard library. It is designed for this task.
具体地说,
Iconv.iconv("utf-8", "utf-16", str).first
应该处理转换.
这篇关于如何将UCS2字符串转换为UTF8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文