ruby 如何判断一个字符串编码是 gbk 还是 utf8
高洛峰
高洛峰 2017-04-24 09:09:43
0
3
708

ruby 如何判断一个字符串编码是 gbk 还是 utf8

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all (3)
PHPzhong

UTF8 encoding and regular expressions

    洪涛

    Use a third-party gem library, rhardet or uchardet is recommended

    2.2.2 :001 > require 'rchardet' => true 2.2.2 :002 > CharDet.detect('测试') => {"encoding"=>"utf-8", "confidence"=>0.7525} 2.2.2 :003 >
      洪涛
      str="abc" sty=str.encoding.name if sty=="GBK" puts "gbk" elsif sty="UTF-8" puts "utf8" else puts "not gbk or utf8" end
        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!