Using string with different encodings


(Gabor Nagypal) #1

Hi,

I have wondered which is the best way in Ruby to deal with strings in
different encodings. E.g. if I have an input file in “UTF-8” encoding
and I would like to produce an output file in “ISO-8859-2” (central
European) encoding (given that the file with the UTF-8 encoding does not
contain characters which cannot be displayed in the ISO-8859-2 encoding,
of course).
In Python I could solve the problem quite elegant using UTF strings, and
the encode-decode functions.
E.g.
value.decode(‘UTF-8’) (load from UTF-8 encoding)
value.encode(‘ISO-8859-2’) (save to ISO-8859-2 encoding)

What do you recommend to achieve the same effect in Ruby?

Thank you,

Gabor


(ccos) #2

hello,
i’m not a perl user.
i have no agenda.
somebody on another list i’m on just
made something of a sweeping statement.
that ruby is slow.
thirty times slower than perl.
there is discussion on that list
about whether to use ruby for a certain project
which is very timing sensitive.
just curious what any of you might have to
say about the aforementioned comparison.
thanks,
c