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
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