How to convert a string's charset?

I want to convert a string's charset from GB2312 or BIG5 to UTF-8. How
can i do
this?

···

--
Posted via http://www.ruby-forum.com/.

Use Iconv:

  # load library
  require 'iconv'

  # create iconv object
  # (be careful: the parameter order is TO, FROM)
  ic = Iconv.new('UTF-8', 'BIG5')

  # convert string
  dst_str = ic.iconv(src_str)

···

* Nanyang Zhan (sxain@hotmail.com) wrote:

I want to convert a string's charset from GB2312 or BIG5 to UTF-8. How
can i do
this?

--
Paul Duncan <pabs@pablotron.org> pabs in #ruby-lang (OPN IRC)
http://www.pablotron.org/ OpenPGP Key ID: 0x82C29562

Paul Duncan wrote:

Use Iconv:

Thanks.
It works,but some strings will raise error, I have to skip them.

···

--
Posted via http://www.ruby-forum.com/\.

You can tell iconv to transliterate or ignore characters that it can't
convert. Appendd //TRANSLIT or //IGNORE to the name of the destination
character set.

···

* Nanyang Zhan (sxain@hotmail.com) wrote:

Paul Duncan wrote:

> Use Iconv:
Thanks.
It works,but some strings will raise error, I have to skip them.

--
Paul Duncan <pabs@pablotron.org> pabs in #ruby-lang (OPN IRC)
http://www.pablotron.org/ OpenPGP Key ID: 0x82C29562