vbs版的urldecode,改自Cooly(☆给我一个开心的理由!☆)写的vb.net版的urldecode

'Cooly(☆给我一个开心的理由!☆)

Public Function URLEncode(strURL)
Dim I
Dim tempStr
For I = 1 To Len(strURL)
    
If Asc(Mid(strURL, I, 1)) < 0 Then
       tempStr 
= "%" & Right(CStr(Hex(Asc(Mid(strURL, I, 1)))), 2)
       tempStr 
= "%" & Left(CStr(Hex(Asc(Mid(strURL, I, 1)))), Len(CStr(Hex(Asc(Mid(strURL, I, 1))))) - 2& tempStr
       URLEncode 
= URLEncode & tempStr
    
ElseIf (Asc(Mid(strURL, I, 1)) >= 65 And Asc(Mid(strURL, I, 1)) <= 90Or (Asc(Mid(strURL, I, 1)) >= 97 And Asc(Mid(strURL, I, 1)) <= 122Then
       URLEncode 
= URLEncode & Mid(strURL, I, 1)
    
Else
       URLEncode 
= URLEncode & "%" & Hex(Asc(Mid(strURL, I, 1)))
    
End If
Next
End Function

Public Function URLDecode(strURL)
Dim I

If InStr(strURL, "%"= 0 Then URLDecode = strURL: Exit Function

For I = 1 To Len(strURL)
    
If Mid(strURL, I, 1= "%" Then
       
If eval("&H" & Mid(strURL, I + 12)) > 127 Then
          URLDecode 
= URLDecode & Chr(eval("&H" & Mid(strURL, I + 12& Mid(strURL, I + 42)))
          I 
= I + 5
       
Else
          URLDecode 
= URLDecode & Chr(eval("&H" & Mid(strURL, I + 12)))
          I 
= I + 2
       
End If
    
Else
       URLDecode 
= URLDecode & Mid(strURL, I, 1)
    
End If
Next
End Function

附vb.net版的urldecode

Private Sub Command1_Click()
Text2.Text 
= URLEncode(Text1.Text)
End Sub



Public Function URLEncode(ByRef strURL As StringAs String
Dim I As Long
Dim tempStr As String
For I = 1 To Len(strURL)
    
If Asc(Mid(strURL, I, 1)) < 0 Then
       tempStr 
= "%" & Right(CStr(Hex(Asc(Mid(strURL, I, 1)))), 2)
       tempStr 
= "%" & Left(CStr(Hex(Asc(Mid(strURL, I, 1)))), Len(CStr(Hex(Asc(Mid(strURL, I, 1))))) - 2& tempStr
       URLEncode 
= URLEncode & tempStr
    
ElseIf (Asc(Mid(strURL, I, 1)) >= 65 And Asc(Mid(strURL, I, 1)) <= 90Or (Asc(Mid(strURL, I, 1)) >= 97 And Asc(Mid(strURL, I, 1)) <= 122Then
       URLEncode 
= URLEncode & Mid(strURL, I, 1)
    
Else
       URLEncode 
= URLEncode & "%" & Hex(Asc(Mid(strURL, I, 1)))
    
End If
Next
End Function


Public Function URLDecode(ByRef strURL As StringAs String
Dim I As Long

If InStr(strURL, "%"= 0 Then URLDecode = strURL: Exit Function

For I = 1 To Len(strURL)
    
If Mid(strURL, I, 1= "%" Then
       
If Val("&H" & Mid(strURL, I + 12)) > 127 Then
          URLDecode 
= URLDecode & Chr(Val("&H" & Mid(strURL, I + 12& Mid(strURL, I + 42)))
          I 
= I + 5
       
Else
          URLDecode 
= URLDecode & Chr(Val("&H" & Mid(strURL, I + 12)))
          I 
= I + 2
       
End If
    
Else
       URLDecode 
= URLDecode & Mid(strURL, I, 1)
    
End If
Next
End Function


Private Sub Command2_Click()
Text3.Text 
= URLDecode(Text2.Text)
End Sub


Private Sub Form_Load()
Text1.Text 
= "http://www.microsoft.com/中国微软"
End Sub
Posted on 2005-03-24 18:11  古代  阅读(1683)  评论(0)    收藏  举报