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
Monday, November 17, 2008
Subscribe to:
Post Comments (Atom)
2 comments:
not sure how this can work... for example:
"&" asc=38 is not converted
"=" asc=61 is not converted
what am i missing???
I think you're right. This code proceeds, I think, from the assumption that you would want to encode an ENTIRE url at once, and thus you'd want to leave &, =, and : so as not to break the URL.
This is not equivalent to @urlencode, which will properly encode url parameters (and break a whole url if you use it that way)
Post a Comment