Search code examples
rubyutf-8ansi

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 the easiest way to do it?


Solution

  • 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)