'----------------------------------------------------------------'
'功能描述: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
'----------------------------------------------------------------'
asp自定义函数:URL编码和解码 区别中英文
原创文章如转载,请注明:转载自悠悠博客 [ http://www.ajaxstu.com/ ]
相关文章:
- Aspjpeg入门详解(2007-11-26 4:56:2)
- ASP操作Excel常见错误(2007-11-15 4:39:21)
- 同一个用户不允许同时登陆两次(2007-11-15 1:17:43)
- 罗列全部session和application(2007-11-12 6:26:16)
- 访问和更新Cookies集合(2007-11-11 1:42:29)
- asp中cookie使用示例(2007-11-7 3:2:28)
- ASPImage组件制作水印的过程(2007-11-4 5:10:36)
- asp重定向-response.redirect和server.transfer(2007-10-24 9:18:30)
- vbscript Replace 函数(2007-10-21 4:33:2)
- asp:Server对象(2007-10-11 7:9:58)
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
