在VB中如何实现URLEncode()
编号:QA002883
建立日期: 2000年4月25日 最后修改日期:2000年4月25日
所属类别:
文章:
李海译自《VBxtras' VBHowTo Issue #40》
是否需要编码文本或其他URL,这样可以在传递给另一个URL作为参数,但是文本中可能包括那些在URL中有特殊意义的字符?在ASP中,你可以使用Server.URLEncode(),但是在VB中如何做?下面是一个函数:
Public Function URLEncode(strInput As String) As String
Dim strOutput As String
Dim intAscii As Integer
Dim i As Integer
For i = 1 To Len(strInput)
intAscii = Asc(Mid(strInput, i, 1))
If ((intAscii < 58) And (intAscii > 47)) Or _
((intAscii < 91) And (intAscii > 64)) Or _
((intAscii < 123) And (intAscii > 96)) Then
strOutput = strOutput & Chr$(intAscii)
Else
strOutput = strOutput & _
IIf(intAscii < 16, "%0", "%") & _
Trim$(Hex$(intAscii))
End If
Next
URLEncode = strOutput
End Function
文章来源:VBxtras。
| |
|
|
| |
|
|