asp学习网: 首页 >> asp自定义函数 >> asp自定义函数:URL编码和解码 区别中英文

asp自定义函数:URL编码和解码 区别中英文

'----------------------------------------------------------------'
'功能描述:URL编码函数
'输入参数:v中英文混合字符串,f是否对ASCII字符编码
'返回值:编码后的ASC字符串
Public Function URLEncoding(v,f)
Dim s,t,i,j,h,l,x : 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)
Dim s,i,l,c,t,n : 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=CInt("&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=CInt("&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
'----------------------------------------------------------------' from:asp学习网/title:asp自定义函数:URL编码和解码 区别中英文/ time:2006-5-19 0:04:21

本文主题asp自定义函数:URL编码和解码 区别中英文

asp教程 ©2006-2007 aspxuexi.com | 关于站点 | 版权隐私 | 站内搜索
复制或者翻版 请于夜间进行