| 赞 | 120 |
| VIP | |
| 好人卡 | |
| 积分 | 194 |
| 经验 | |
| 最后登录 | 2026-7-4 |
| 在线时间 | 3082 小时 |
- 梦石
- 0
- 星屑
- 19426
- 在线时间
- 3082 小时
- 注册时间
- 2013-1-11
- 回帖
- 1207
|
发表于 2017-7-19 17:08:18
|
显示全部楼层
插入到main之前
[pre lang="ruby"]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[/pre]
在事件里写上
[pre lang="ruby"]File.open("a.txt","r") do |f|
s = ""
while line = f.gets
s += line
end
print s.gb2312_to_utf8
end[/pre] |
评分
-
查看全部评分
|