VB,VBS,实现server.URLEncode及反编码功能的函数URLEncode()与URLDecode()

 URLEncode(strURL)
     I
     tempStr
     I  1  (strURL)
         ((strURL, I, 1))  0 
            tempStr    (((((strURL, I, 1)))), 2)
            tempStr    (((((strURL, I, 1)))), (((((strURL, I, 1)))))  2)  tempStr
            URLEncode  URLEncode  tempStr
         (((strURL, I, 1))  65  ((strURL, I, 1))  90)  (((strURL, I, 1))  97  ((strURL, I, 1))  122)  (((strURL, I, 1))  48  ((strURL, I, 1))  57) 
            URLEncode  URLEncode  (strURL, I, 1)
        
            URLEncode  URLEncode    (((strURL, I, 1)))
         
    
 

 URLDecode(strURL)
     I

     (strURL, )  0 
        URLDecode  strURL
         
     

     I  1  (strURL)
         (strURL, I, 1)   
             (  (strURL, I  1, 2))  127 
                URLDecode  URLDecode  ((  (strURL, I  1, 2)  (strURL, I  4, 2)))
                I  I  5
            
                URLDecode  URLDecode  ((  (strURL, I  1, 2)))
                I  I  2
             
        
            URLDecode  URLDecode  (strURL, I, 1)
         
    
 

 

 

 

 1  < script language = vbs >
 2  Function  URLEncode(strURL)
 3       Dim  I
 4       Dim  tempStr
 5       For  I  =   1   To   Len (strURL)
 6           If   Asc ( Mid (strURL, I,  1 ))  <   0   Then
 7              tempStr  =   " % "   &   Right ( CStr ( Hex ( Asc ( Mid (strURL, I,  1 )))),  2 )
 8              tempStr  =   " % "   &   Left ( CStr ( Hex ( Asc ( Mid (strURL, I,  1 )))),  Len ( CStr ( Hex ( Asc ( Mid (strURL, I,  1 )))))  -   2 &  tempStr
 9              URLEncode  =  URLEncode  &  tempStr
10           ElseIf  ( Asc ( Mid (strURL, I,  1 ))  >=   65   And   Asc ( Mid (strURL, I,  1 ))  <=   90 Or  ( Asc ( Mid (strURL, I,  1 ))  >=   97   And   Asc ( Mid (strURL, I,  1 ))  <=   122 Or  ( Asc ( Mid (strURL, I,  1 ))  >=   48   And   Asc ( Mid (strURL, I,  1 ))  <=   57 Then
11              URLEncode  =  URLEncode  &   Mid (strURL, I,  1 )
12           Else
13              URLEncode  =  URLEncode  &   " % "   &   Hex ( Asc ( Mid (strURL, I,  1 )))
14           End   If
15       Next
16  End Function
17 
18  Function  URLDecode(strURL)
19       Dim  I
20      
21       If   InStr (strURL,  " % " =   0   Then
22          URLDecode  =  strURL
23           Exit   Function
24       End   If
25      
26       For  I  =   1   To   Len (strURL)
27           If   Mid (strURL, I,  1 =   " % "   Then
28               If   Eval ( " &H "   &   Mid (strURL, I  +   1 2 ))  >   127   Then
29                  URLDecode  =  URLDecode  &   Chr ( Eval ( " &H "   &   Mid (strURL, I  +   1 2 &   Mid (strURL, I  +   4 2 )))
30                  I  =  I  +   5
31               Else
32                  URLDecode  =  URLDecode  &   Chr ( Eval ( " &H "   &   Mid (strURL, I  +   1 2 )))
33                  I  =  I  +   2
34               End   If
35           Else
36              URLDecode  =  URLDecode  &   Mid (strURL, I,  1 )
37           End   If
38       Next
39  End Function
40 
41  msgbox  URLEncode( " 我是谁呀haha " ),, " URLEncode(""我是谁呀haha"") "
42  msgbox  URLEncode( " yongfa365 " ),, " URLEncode(""yongfa365"") "
43  msgbox  URLEncode( " How are you ? " ),, " URLEncode(""How are you ?"") "
44  msgbox  URLDecode(URLEncode( " 我是谁呀haha " )),, " URLDecode(URLEncode(""我是谁呀haha"")) "
45  window.close()
46  </ script >
47 

 

 

转载于:https://www.cnblogs.com/xxaxx/archive/2009/12/29/1635302.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值