VB URLEncode

'url编码
Function URLEncode(strParameter)
Dim s As String
Dim I As Integer
Dim intValue As Integer

Dim TmpData() As Byte

        s = ""
        TmpData = StrConv(strParameter, vbFromUnicode)
        For I = 0 To UBound(TmpData)
                intValue = TmpData(I)
                If (intValue >= 48 And intValue <= 57) Or _
                        (intValue >= 65 And intValue <= 90) Or _
                        (intValue >= 97 And intValue <= 122) Then
                        s = s & Chr(intValue)
                ElseIf intValue = 32 Then
                        s = s & "+"
                Else
                        s = s & "%" & getTwo(Hex(intValue))
                End If
        Next I
        URLEncode = s

End Function 

Function getTwo(str)

    If Len(str) <> 2 Then
        getTwo = "0" & str
    Else
        getTwo = str
    End If

End Function

 

posted @ 2013-09-08 20:07  巫妖天下  阅读(256)  评论(0编辑  收藏  举报