1,502
社区成员
发帖
与我相关
我的任务
分享
'功能描述: URL编码函数
'输入参数:v中英文混合字符串,f是否对ASCII字符编码
'返回值:编码后的ASC字符串
Public Function URLEncoding(v As String, f As Boolean)
Dim s As String, t As String, i As Integer, j As Long, h As Long, l As Long, x As Integer
s = "": x = Len(v)
For i = 1 To x
t = Mid(v, i, 1): j = Asc(t)
If j > 0 Then
If f Then
s = s & "%" & Right("00" & Hex(Asc(t)), 2)
Else
s = s & t
End If
Else
If j < 0 Then j = j + &H10000
h = (j And &HFF00) \ &HFF
l = j And &HFF
s = s & "%" & Hex(h) & "%" & Hex(l)
End If
Next
URLEncoding = s
End Function
'----------------------------------------------------------------'
'功能描述:URL解码码函数
'输入参数:vURL编码的字符串
'返回值:解码后的字符串
Public Function URLDecoding(sIn As String) As String
Dim s As String, i As Integer, l As Integer, c As String, t As Long, n As Integer
s = "": l = Len(sIn)
For i = 1 To l
c = Mid(sIn, i, 1)
If c <> "%" Then
s = s & c
Else
c = Mid(sIn, i + 1, 2): i = i + 2: t = Val("&H" & c)
If t < &H80 Then
s = s & Chr(t)
Else
c = Mid(sIn, i + 1, 3)
If Left(c, 1) <> "%" Then
URLDecoding = s
Exit Function
Else
c = Right(c, 2): n = Val("&H" & c)
t = t * 256 + n - 65536
s = s & Chr(t): i = i + 3
End If
End If
End If
Next
URLDecoding = s
End Function