VB URL编码与解码

网上搜到的基本都有问题,编码不正常。这个是自己修改过的完全正常。

Public Function UrlEncoding(StrX As String) As String 'URL编码
On Error GoTo over
Dim i, StrReturn As String, Thischr, Innercode
    StrReturn = ""
    For i = 1 To Len(StrX)
        Thischr = Mid(StrX, i, 1)
        If Abs(Asc(Thischr)) < &HFF Then
            If Thischr = " " Then
                StrReturn = StrReturn & "+"
            ElseIf InStr("!""#$%&'()*+,/:;<=>?@[\]^`{|}~%", Thischr) > 0 Then
                StrReturn = StrReturn & "%" & Hex(Asc(Thischr))
            Else
                StrReturn = StrReturn & Thischr
            End If
        Else
            Innercode = Asc(Thischr)
            If Innercode < 0 Then Innercode = Innercode + &H10000
            StrReturn = StrReturn & "%" & Hex((Innercode And &HFF00) \ &HFF) & "%" & Hex(Innercode And &HFF)
        End If
    Next
UrlEncoding = StrReturn
Exit Function
over:
UrlEncoding = ""
End Function
---------------------------------------------------------------------
Public Function URLDecode(ByRef strURL As String) As String 'URL解码
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 + 1, 2)) > 127 Then
URLDecode = URLDecode & Chr(Val("&H" & Mid(strURL, I + 1, 2) & Mid(strURL, I + 4, 2)))
I = I + 5
Else
URLDecode = URLDecode & Chr(Val("&H" & Mid(strURL, I + 1, 2)))
I = I + 2
End If
Else
URLDecode = URLDecode & Mid(strURL, I, 1)
End If
Next
End Function