转换反斜杠u字符串Unicode编码decodeu函数4个 Autohotkey

本文来自于Thinkai’s Blog,thinkai也是我在ahk上面的引路人,对thinkai感兴趣的朋友请关注他的博客。
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)
}

 

给TA捐赠
共{{data.count}}人
人已捐赠
其他教程

获取http-only只读cookie Autohotkey

2020-2-19 10:32:40

其他教程案例

判断文件是否带UTF-8 BOM示例 Autohotkey 

2020-2-19 10:35:46

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
有新私信 私信列表
搜索