urlencode(string){ string := Ansi2UTF8(string) StringLen, len, string Loop % len { SetFormat, IntegerFast, hex StringMid, out, string, %A_Index%, 1 hex := Asc(out) hex2 := hex StringReplace, hex, hex, 0x, , All SetFormat, IntegerFast, d hex2 := hex2 If (hex2==33 || (hex2>=39 && hex2 <=42) || hex2==45 || hex2 ==46 || (hex2>=48 && hex2<=57) || (hex2>=65 && hex2<=90) || hex2==95 || (hex2>=97 && hex2<=122) || hex2==126) content .= out Else content .= "`%" hex } Return content } urldecode(string){ StringReplace, string, string, +, %A_Space%, All ;去连接符 Loop, Parse, string, `% { asc_key := A_LoopField if A_index = 1 content = % content asc_key ;直接串接 Else { if RegExMatch(asc_key,"i)[0-9a-f]{2}") { StringLeft, part1, asc_key, 2 ;分成两部分 hex 和单字节字符 StringTrimLeft, part2, asc_key, 2 asc_var := chr("0x" part1) content = % content asc_var part2 } Else content = % content asc_key ;直接串接 } } return content } Ansi2UTF8(sString) { Ansi2Unicode(sString, wString, 0) Unicode2Ansi(wString, zString, 65001) Return zString } UTF82Ansi(zString) { Ansi2Unicode(zString, wString, 65001) Unicode2Ansi(wString, sString, 0) Return sString } Ansi2Unicode(ByRef sString, ByRef wString, CP = 0) { nSize := DllCall("MultiByteToWideChar" , "Uint", CP , "Uint", 0 , "Uint", &sString , "int", -1 , "Uint", 0 , "int", 0) VarSetCapacity(wString, nSize * 2) DllCall("MultiByteToWideChar" , "Uint", CP , "Uint", 0 , "Uint", &sString , "int", -1 , "Uint", &wString , "int", nSize) } 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) } ;测试 a := urlencode("Round(Number [, N]): 如果 N 省略或为 0, 则 Number 被取整到最近的整数. 如果 N 为正数, 则 Number 被取整到 N 个小数位. 如果 N 为负数,则 Number 被取整到十进制小数点左边 N 位。例如,Round(345, -1) 的结果为 350 而 Round (345, -2) 的结果为 300。与 Transform Round 不同, 每当 N 省略或小于 1 时结果不带 .000 后缀. 在 v1.0.44.01+,N 值大于零时会准确显示 N 个小数位而不遵循 SetFormat 的设置。要避免这种情况, 需要对 Round() 的返回值再进行一次数学运算; 例如: Round(3.333, 1)+0.") Clipboard = % a b := urldecode(a) FileDelete, %A_Temp%\a.tmp FileAppend, %b%, %A_Temp%\a.tmp FileEncoding, UTF-8 FileRead, b, %A_Temp%\a.tmp MsgBox, 编码:`n%a%`n解码:`n%b% str := "%E5%BD%93%E5%89%8D%E4%BD%8D%E7%BD%AE%EF%BC%9A%E7%83%AD%E9%97%A8%E5%B7%A5%E5%85%B7%E5%89%8D20%E5%90%8D" MsgBox % UTF82Ansi(urldecode(str))
49 queries in 1.336 seconds |