How to do charset conversion in ruby?

hello all,
say I've get a file encoding in GB2312,
how do I convert it to UTF-8?

How about a good old RTFM ? :wink:

http://www.ruby-doc.org/ is your friend.

Check out this page for the iconv wrapper

http://www.ruby-doc.org/stdlib/libdoc/iconv/rdoc/classes/Iconv.html

···

On Wed, 20 Jul 2005 08:31:39 +0200, femtowin femtowin <femtowin@gmail.com> wrote:

hello all,
say I've get a file encoding in GB2312,
how do I convert it to UTF-8?

--
Katarina

require 'iconv'
conv = Iconv.new("UTF16","ISO88591")
result = conv.iconv("hello")

but it reports: No such file to load -- iconv,
I'm under windows.
and the manual says Iconv is a wrapper class for the UNIX 95 iconv()
function family,so is that iconv must be used under UNIX/LINUX?
or should I install something?

···

On 7/20/05, Katarina WONG <k.wong@laposte.net> wrote:

On Wed, 20 Jul 2005 08:31:39 +0200, femtowin femtowin <femtowin@gmail.com> > wrote:

> hello all,
> say I've get a file encoding in GB2312,
> how do I convert it to UTF-8?
>

How about a good old RTFM ? :wink:

http://www.ruby-doc.org/ is your friend.

Check out this page for the iconv wrapper

http://www.ruby-doc.org/stdlib/libdoc/iconv/rdoc/classes/Iconv.html

--
Katarina

I've found out the problem,
http://wiki.rubyonrails.com/rails/show/iconv
says how to cope with it,

thanks,Katarina

···

On 7/21/05, femtowin femtowin <femtowin@gmail.com> wrote:

require 'iconv'
conv = Iconv.new("UTF16","ISO88591")
result = conv.iconv("hello")

but it reports: No such file to load -- iconv,
I'm under windows.
and the manual says Iconv is a wrapper class for the UNIX 95 iconv()
function family,so is that iconv must be used under UNIX/LINUX?
or should I install something?

On 7/20/05, Katarina WONG <k.wong@laposte.net> wrote:
> On Wed, 20 Jul 2005 08:31:39 +0200, femtowin femtowin <femtowin@gmail.com> > > wrote:
>
> > hello all,
> > say I've get a file encoding in GB2312,
> > how do I convert it to UTF-8?
> >
>
> How about a good old RTFM ? :wink:
>
> http://www.ruby-doc.org/ is your friend.
>
> Check out this page for the iconv wrapper
>
> http://www.ruby-doc.org/stdlib/libdoc/iconv/rdoc/classes/Iconv.html
>
>
>
> --
> Katarina
>
>