Alex Young
5/14/2007 2:48:00 PM
Claus Hausberger wrote:
> Hello
>
> I have a lot of xml and java files witch have German Umlauts and other
> non ASCII files in them.
>
> I want to read the files and convert them to UTF-8 using a Ruby script.
>
> I convert the strings with this code:
>
> def to_utf8(str)
> str.unpack('U*').map do |c|
I'd be surprised if this was right - you're telling it that you're
expecting the string to be UTF-8 already with that unpack format.
<snip>
> how can I read a file with Ruby and specify that it is read with
> ISO-8859-1 encoding (similar to Java's BufferedReader where I can
> specify the encoding).
Investigate Iconv in the standard library. It does what you need.
--
Alex