class String CP_ACP = 0 CP_UTF8 = 65001 def gb2312_to_utf8 m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i') w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i') n = self.size i = m2w.call(CP_ACP, 0, self, n+1, nil, 0) buffer = "\0" * (i*2) m2w.call(CP_ACP, 0, self, n+1, buffer, i) i = w2m.call(CP_UTF8, 0, buffer, -1, nil, 0, nil, nil) result = "\0" * i w2m.call(CP_UTF8, 0, buffer, -1, result, i, nil, nil) result.chop! return result end end
File.open("a.txt","r") do |f| s = "" while line = f.gets s += line end print s.gb2312_to_utf8 end
张咚咚 发表于 2017-7-19 17:08
插入到main之前
class String
QQ截图20170719194138.png (19.82 KB, 下载次数: 17)
QQ截图20170719194203.png (2.58 KB, 下载次数: 15)
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |