Convert latin1 string to utf8?

brainfck picture brainfck · Oct 7, 2009 · Viewed 7k times · Source

how can I convert a string, that contains latin1 characters to utf8?

The string is a document, that is opened by open-uri and that contains these special characters.

Best regards

Answer

Jonathan Feinberg picture Jonathan Feinberg · Oct 7, 2009

Iconv

require 'iconv'
i = Iconv.new('UTF-8','LATIN1')
a_with_hat = i.iconv("\xc2")