About This Code
Brief Description:
LotusScript version of JavaScript's escape function
Notes Version:
R5.x, R6.x
Last Modified:
20 Aug 2002
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
Thanks to Emanuel Moecklin for posting this to the ldd Gold forum!
Function Escape(s As String) As String
%REM
Encodes a string to the "x-www-form-urlencoded" form, enhanced with the UTF-8-in-URL proposal. This is the official
standard to encode URL's to support any possible character set (all Unicode characters).
%END REM
Dim result As String
Dim i As Integer
Dim c As Long
For i = 1 To Len(s)
c = Uni(Mid$(s, i, 1))
If c = Uni(" ") Then
result = result + "+"
Elseif (c>=Uni("A") And c<=Uni("Z")) Or (c>=Uni("a") And c<=Uni("z")) Or (c>=Uni("0") And c<=Uni("9")) Then
result = result + Uchr(c)
Elseif c <= &H007f Then
result = result + "%" + Hex$(c)
Elseif c <= &H07FF Then
result = result + "%" + Hex$(&Hc0 Or (c\64))
result = result + "%" + Hex$(&H80 Or (c And &h3F))
Else
result = result + "%" + Hex$(&Hc0 Or (c\4096))
result = result + "%" + Hex$(&H80 Or ((c\64) And &H3F))
result = result + "%" + Hex$(&H80 Or (c And &H3F))
End If
Next
Escape = result
End Function
Usage / Example