tags:

views:

239

answers:

3

I have a Ruby script that generates a ANSI file.

I want to converting ANSI to UTF8 file.

What's the easiest way to do it?

+2  A: 

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)
S.Mark
I solution my problem.My code is:text=Iconv.iconv('UTF-8', 'gb2312',text)
HelloWorld
Oh, ok, I didn't know your encoding was 'gb2312', so I put 'ascii' as example. You should have asked gb2312 to UTF8 in question. but anyway, glad to know its works.
S.Mark
A: 

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.

Alex Martelli
+1  A: 

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.

Michael Aaron Safyan