您的位置:首页 > 理论基础 > 计算机网络

单位网络使用路由器进行上网限制

2010-07-05 23:02 260 查看
出以下错误
in `split': invalid byte sequence in GBK (ArgumentError)

解决方案:
require "iconv"

class String
def to_gbk
Iconv.iconv("GBK//IGNORE", "UTF-8//IGNORE", self).to_s
end

def to_utf8
#p "my own string"
Iconv.iconv("UTF-8//IGNORE", "GBK//IGNORE", self).to_s
end

def to_utf8_valid

if !self.valid_encoding?
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
return ic.iconv(self)
end
self
end

end
puts "读取文件"
f=File.open("boss2.txt", 'r')
i=0
total=0
f.each_line do |line|
i+=1

line_arr=line.to_utf8_valid.split(/\t/)
len =line_arr.length
if (len!=41)
puts "line: #{line_arr[0]} #{len}"
total+=1
end
#puts(i,len)
end
puts "total:#{total}"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐