I want to convert a string’s charset from GB2312 or BIG5 to UTF-8. How
can i do
this?
- Nanyang Z. ([email protected]) wrote:
I want to convert a string’s charset from GB2312 or BIG5 to UTF-8. How
can i do
this?
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)
Paul D. wrote:
Use Iconv:
Thanks.
It works,but some strings will raise error, I have to skip them.
- Nanyang Z. ([email protected]) wrote:
Paul D. wrote:
Use Iconv:
Thanks.
It works,but some strings will raise error, I have to skip them.
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.