22 lines
636 B
Plaintext
22 lines
636 B
Plaintext
Function URLEncode(Data As String, ParamArray Exceptions() As String) As String
|
|
Dim buf As String
|
|
For i As Integer = 1 To Data.Len
|
|
Dim char As String = Data.Mid(i, 1)
|
|
Select Case Asc(char)
|
|
Case 48 To 57, 65 To 90, 97 To 122, 45, 46, 95
|
|
buf = buf + char
|
|
Else
|
|
If Exceptions.IndexOf(char) > -1 Then
|
|
buf = buf + char
|
|
Else
|
|
buf = buf + "%" + Left(Hex(Asc(char)) + "00", 2)
|
|
End If
|
|
End Select
|
|
Next
|
|
Return buf
|
|
End Function
|
|
|
|
'usage
|
|
Dim s As String = URLEncode("http://foo bar/") ' no exceptions
|
|
Dim t As String = URLEncode("http://foo bar/", "!", "?", ",") ' with exceptions
|