1个回答
展开全部
我发你编码和解码的vb实现代码:
Private Function URLEncode(ByVal strURL As String) As String
Dim i As Long
Dim tempStr As String
For i = 1 To Len(strURL)
If InStr("-,.0123456789", Mid(strURL, i, 1)) Then
URLEncode = URLEncode & Mid(strURL, i, 1)
Else
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)) <= 90) Or (Asc(Mid(strURL, i, 1)) >= 97 And Asc(Mid(strURL, i, 1)) <= 122) Then
URLEncode = URLEncode & Mid(strURL, i, 1)
Else
URLEncode = URLEncode & "%" & Hex(Asc(Mid(strURL, i, 1)))
End If
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 + 1, 2)) > 127 Then
URLDecode = URLDecode & Chr(eval("&H" & Mid(strURL, I + 1, 2) & Mid(strURL, I + 4, 2)))
I = I + 5
Else
URLDecode = URLDecode & Chr(eval("&H" & Mid(strURL, I + 1, 2)))
I = I + 2
End If
Else
URLDecode = URLDecode & Mid(strURL, I, 1)
End If
Next
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询