Encoding::UndefinedConversionError

arr=line.force_encoding("utf-8").split("\t")

出现:`encode’: “\xAF\xD0” from GBK to UTF-8 (Encoding::UndefinedConversionError)

更改为以下
arr= line.encode('UTF-8',{
:invalid => :replace,
:undef   => :replace,
:replace => '?'
}).split("\t")

发表评论