gb2312 gbk gb18030 到 utf8 的转换 互转
ruby吧
全部回复
仅看楼主
level 9
sevk 楼主
#!/usr/bin/env ruby -w
# coding: utf-8
require 'pathname'
#require 'rchardet'
require 'iconv'
class String
   def to_gb
     Iconv.conv("gb2312//IGNORE","UTF-8//IGNORE",self)
   end
   def utf8_to_gb
     Iconv.conv("gb2312//IGNORE","UTF-8//IGNORE",self)
   end
   def gb_to_utf8
     Iconv.conv("UTF-8//IGNORE","GB18030//IGNORE",self)
   end
   def to_utf8
     Iconv.conv("UTF-8//IGNORE","GB18030//IGNORE",self)
   end
end

2010年08月26日 01点08分 1
level 9
sevk 楼主
用法:
print "中国".utf8_to_gb
print "中国".to_gb
2010年08月26日 02点08分 2
1