本文来自于Thinkai’s Blog,thinkai也是我在ahk上面的引路人,对thinkai感兴趣的朋友请关注他的博客。
thinkai的博客简洁、有趣,即便是转载过来我也尽量保持作者原有的风格,主要是方便大家查阅。转换效率 decodeu3>decodeu4>decodeu2>decodeu
thinkai的博客简洁、有趣,即便是转载过来我也尽量保持作者原有的风格,主要是方便大家查阅。转换效率 decodeu3>decodeu4>decodeu2>decodeu
使用环境Autohotkey ansi32,输出gb2312字符串
decodeu2(out){
foundpos := 1
while(foundpos := RegExMatch(out,"\u([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})",m))
Unicode2Ansi(Chr("0x" m2) Chr("0x" m1),tmpstr,0),out := RegExReplace(out,"\u" m1 m2, tmpstr)
return out
}
decodeu3(out){
foundpos := 1
while(foundpos := RegExMatch(out,"\u([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})",m))
Unicode2Ansi(Chr("0x" m2) Chr("0x" m1),tmpstr,0),out := strReplace(out,"u" m1 m2, tmpstr)
return out
}
decodeu4(out){
foundpos := 1, VarSetCapacity(char,3,0)
while(foundpos := RegExMatch(out,"\u([A-Fa-f0-9]{4})",m))
NumPut("0x" m1,&char,,"UShort"),out := strReplace(out,"u" m1 m2, StrGet(&char,,"CP1200"))
return out
}
decodeu(ustr){
Loop
{
if !ustr
break
if RegExMatch(ustr,"^s*\u([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})(.*)",m)
{
word_u := Chr("0x" m2) Chr("0x" m1), ustr := m3, word_a := ""
Unicode2Ansi(word_u,word_a,0)
out .= word_a
}
else if RegExMatch(ustr, "^([a-zA-Z0-9.?-!s:""]*)(.*)",n)
{
ustr := n2
out .= n1
}
}
return out
}
Unicode2Ansi(ByRef wString, ByRef sString, CP = 0)
{
nSize := DllCall("WideCharToMultiByte"
, "Uint", CP
, "Uint", 0
, "Uint", &wString
, "int", -1
, "Uint", 0
, "int", 0
, "Uint", 0
, "Uint", 0)
VarSetCapacity(sString, nSize)
DllCall("WideCharToMultiByte"
, "Uint", CP
, "Uint", 0
, "Uint", &wString
, "int", -1
, "str", sString
, "int", nSize
, "Uint", 0
, "Uint", 0)
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。