浙林龙哥

   :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 

Public Function urlDecode(s As String) As String
	If Len(s) = 0 Then Exit Function
	Dim i As Integer
	Dim tmp As String
	Dim c As String
	For i = 1 To Len(s)
		c = Mid$(s, i, 1)
		If c = "+" Then c = " "
		If c = "%" Then
			c = Chr$("&H" + Mid$(s, i + 1, 2))
			i = i + 2
		End If
		tmp = tmp + c
	Next i
	urlDecode = tmp
End Function

Public Function urlEncode(s As String) As String
	If Len(s) = 0 Then Exit Function
	
	Dim tmp As String
	Dim c As String
	Dim i As Integer
	
	For i = 1 To Len(s)
		c = Mid(s, i, 1)
		If (Asc(c) >= 65 And Asc(c) <= 90) _
		Or (Asc(c) >= 97 And Asc(c) <= 122) _
		Or (Asc(c) >= 48 And Asc(c) <= 58) _
		Or Asc(c) = 38 _
		Or (Asc(c) >= 45 And Asc(c) <= 47) _
		Or Asc(c) = 58 Or Asc(c) = 61 _
		Or Asc(c) = 63 Or Asc(c) = 126 Then
			tmp = tmp + c
		Else
			tmp = tmp + "%" + Hex(Asc(c))
		End If
	Next i
	urlEncode = tmp
End Function
posted on 2004-08-06 09:39  浙林龙哥  阅读(1596)  评论(0编辑  收藏  举报