VB URL编码函数
VB UTF-8 URL编码函数:
VB GB2312 URL编码函数:
-
Public Function UTF8_URLEncoding(szInput)
-
Dim wch, uch, szRet
-
Dim x
-
Dim nAsc, nAsc2, nAsc3
-
If szInput = "" Then
-
UTF8_URLEncoding = szInput
-
Exit Function
-
End If
-
For x = 1 To Len(szInput)
-
wch = Mid(szInput, x, 1)
-
nAsc = AscW(wch)
-
-
If nAsc < 0 Then nAsc = nAsc + 65536
-
-
If (nAsc And &HFF80) = 0 Then
-
szRet = szRet & wch
-
Else
-
If (nAsc And &HF000) = 0 Then
-
uch = "%" & Hex(((nAsc \ 2 ^ 6)) Or &HC0) & Hex(nAsc And &H3F Or &H80)
-
szRet = szRet & uch
-
Else
-
uch = "%" & Hex((nAsc \ 2 ^ 12) Or &HE0) & "%" & _
-
Hex((nAsc \ 2 ^ 6) And &H3F Or &H80) & "%" & _
-
Hex(nAsc And &H3F Or &H80)
-
szRet = szRet & uch
-
End If
-
End If
-
Next
-
UTF8_URLEncoding = szRet
- End Function
-
Public Function URLEncode(ByRef strURL)
-
Dim I
-
Dim tempStr
-
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