URL编码 函数转化问题
原ASP代码:Function UrlUncode(str)
okstr = ""
hexvalue = "&H"
starthx = 0
slen = len(str)
for i=1 to slen
c = mid(str,i,1)
if starthx = 0 then
if c="%" then
starthx = 1
else
okstr = okstr & c
end if
else
if c<>"%" then
hexvalue = hexvalue & c
end If
If len(hexvalue) = 4 then
If hexvalue<&H81 then
okstr = okstr & chr(hexvalue)
hexvalue = "&H"
starthx = 0
End If
End If
If len(hexvalue) = 6 then
okstr = okstr & chr(hexvalue)
hexvalue = "&H"
starthx = 0
End If
End if
next
UrlUncode = okstr
End Function
我转化的autoit函数代码:
Func UrlUncode($str)
$okstr = ""
$hexvalue = "&H"
$starthx = 0
$slen = StringLen ($str)
for $i=1 to $slen
$c = StringMid($str,$i,1)
if $starthx = 0 then
if $c="%" then
$starthx = 1
else
$okstr = $okstr & $c
EndIf
else
if $c<>"%" then
$hexvalue = $hexvalue & $c
EndIf
If StringLen($hexvalue) = 4 then
If $hexvalue<"&H81" then
$okstr = $okstr & chr($hexvalue)
$hexvalue = "&H"
$starthx = 0
EndIf
EndIf
If StringLen($hexvalue) = 6 then
$okstr = $okstr & chr($hexvalue)
$hexvalue = "&H"
$starthx = 0
EndIf
EndIf
next
Return $okstr
EndFunc
我不知道哪里错了..URL解码不行~[原来chr函数...跟asp里面的chr功能差远了..貌似哈,不大确切]
[ 本帖最后由 e5907 于 2008-7-16 09:36 编辑 ] 试试这个
MsgBox(0,0,_UnicodeURLEncode("autoit中文论坛"))
Func _UnicodeURLEncode($UnicodeURL) ;==>_UnicodeURLEncode
Local $UnicodeBinaryLength,$UnicodeBinary,$UnicodeBinary2
$UnicodeBinary = StringToBinary ($UnicodeURL,4)
$UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1)
$UnicodeBinaryLength = StringLen($UnicodeBinary2)
Local $EncodedString,$UnicodeBinaryChar,$EncodedString
For $i = 1 To $UnicodeBinaryLength Step 2
$UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2)
If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString ('0x' & $UnicodeBinaryChar,4)) Then
$EncodedString &= BinaryToString ('0x' & $UnicodeBinaryChar)
Else
$EncodedString &= '%' & $UnicodeBinaryChar
EndIf
Next
Return $EncodedString
EndFunc pcbar兄出马,果然厉害!
您给出的是Unicode的编码方式......我看能不能自己弄成我需要的方式..这个问题算已解决吧!
感谢斑竹,送上笑话一个..
熊对能说:穷成这样啦,四个熊掌全卖了;
兵对丘说:兄弟,踩上地雷了吧,两腿咋都没了?
王对皇说:当皇上有什么好处,你看,头发都白了;
口对回说:亲爱的,都怀孕这么久了,也不说一声;
果对裸说:哥们儿,你穿上衣服还不如不穿!
比对北说:夫妻何必闹离婚呢?
巾对币说:戴上博士帽就身价百倍了;
臣对巨说:一样的面积,但我是三室两厅! 发现一个问题:
$buffer = StringToBinary("网络工具下载工具", 1)
MsgBox(4096, "提示:(Ansi模式)" , $buffer)
$buffer = BinaryToString($buffer, 1)
MsgBox(4096, "提示:(Ansi模式)" , $buffer)
不能还原...导致我解码失败..无语! 回复 2# pcbar
解决了问题,谢谢! 果然厉害!谢谢! 这个将来会有用地,非常感谢
页:
[1]