开发者

Converting ANSI to UTF8 with Ruby

I have a Ruby script that generates an ANSI file.

I want to convert the file to UTF8.

What's th开发者_JS百科e easiest way to do it?


If your data is between ascii range 0 to 0x7F, its valid UTF8, so you don't need to do anything.

Or, if there is characters above 0x7F, you could use Iconv

text=Iconv.iconv('UTF-8', 'ascii',text)


The 8-bit Unicode Transformation Format (UTF-8) was designed to be backwards compatible with the American Standard Code for Information Interchange (ASCII). Therefore, by definition, any valid ASCII sequence is also a valid UTF-8 sequence. For more information, read the UTF FAQ and Unicode FAQ.


Any ASCII file is a valid UTF8 file, going by your Q's title, so no conversion is needed. I don't know what a UIF8 file is, going by your Q's text, so different from its title.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜