本脚本来自于Thinkai的博客,仅作为归档。
urlencode(string,encoding:="UTF-8"){
VarSetCapacity(pstr,ceil(strlen(string)*1.5+10),0)
StrPut(string,&pstr,,encoding)
int := "1"
while (int){
int := ToBase(NumGet(&pstr,(A_index-1)*4,"Uint"),16)
RegExMatch(int,"(.{2})(.{2})(.{2})(.{2})",m)
loop 4
{
i := 4-A_index+1
hex := % m%i%
if hex
{
hex2 := "0x" hex
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)
out .= chr("0x" hex)
else
out .= "%" hex
}
}
}
Return out
}
ToBase(n,b){
return (n < b ? "" : ToBase(n//b,b)) . ((d:=Mod(n,b)) < 10 ? d : Chr(d+55))
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。