赞 | 123 |
VIP | 13 |
好人卡 | 16 |
积分 | 195 |
经验 | 38692 |
最后登录 | 2024-11-27 |
在线时间 | 3111 小时 |
Lv4.逐梦者
- 梦石
- 0
- 星屑
- 19488
- 在线时间
- 3111 小时
- 注册时间
- 2013-1-11
- 帖子
- 1292
|
插入到main之前
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
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
File.open("a.txt","r") do |f|
s = ""
while line = f.gets
s += line
end
print s.gb2312_to_utf8
end
|
评分
-
查看全部评分
|