找回密码
 加入
搜索
查看: 4287|回复: 6

URL编码 函数转化问题

[复制链接]
发表于 2008-7-15 20:05:57 | 显示全部楼层 |阅读模式
原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 编辑 ]
发表于 2008-7-15 21:28:40 | 显示全部楼层
试试这个

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

评分

参与人数 1金钱 +10 收起 理由
chamlien + 10 解决了问题,谢谢!

查看全部评分

 楼主| 发表于 2008-7-16 09:35:38 | 显示全部楼层
pcbar兄出马,果然厉害!
您给出的是Unicode的编码方式......我看能不能自己弄成我需要的方式..这个问题算已解决吧!
感谢斑竹,送上笑话一个..

熊对能说:穷成这样啦,四个熊掌全卖了;
兵对丘说:兄弟,踩上地雷了吧,两腿咋都没了?
王对皇说:当皇上有什么好处,你看,头发都白了;
口对回说:亲爱的,都怀孕这么久了,也不说一声;
果对裸说:哥们儿,你穿上衣服还不如不穿!
比对北说:夫妻何必闹离婚呢?
巾对币说:戴上博士帽就身价百倍了;
臣对巨说:一样的面积,但我是三室两厅!
 楼主| 发表于 2008-7-16 10:17:56 | 显示全部楼层
发现一个问题:
 
$buffer = StringToBinary("网络工具下载工具", 1)
MsgBox(4096, "提示:(Ansi模式)" , $buffer)
$buffer = BinaryToString($buffer, 1)
MsgBox(4096, "提示:(Ansi模式)" , $buffer)


不能还原...导致我解码失败..无语!
发表于 2016-5-2 19:12:20 | 显示全部楼层
回复 2# pcbar


    解决了问题,谢谢!
发表于 2016-12-27 14:38:14 | 显示全部楼层
果然厉害!谢谢!
发表于 2016-12-28 12:24:36 | 显示全部楼层
这个将来会有用地,非常感谢
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-25 19:45 , Processed in 0.075103 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表