URL Escape and Unescape in LotusScript

JavaScript contains a handy built-in function, 'escape', that encodes text so that it can appear as part of a URL. For instance, the space character is changed to %20, ampersand to %3B, and so on. The 'unescape' function converts these "percent" codes back to their original representation.

These are helpful functions to have available when you write Domino agents. These agents could use unescape to read arguments from their own URLs, and use escape when they need to print a new URL when they finish execution.

Here are LotusScript implementations for these functions:


Function escape(Byval s$) As String
' Scan a string for characters that aren't OK to appear in a URL and change them to "%" hex codes.
' This is intended to be as nearly as possible a match for the same name function in JavaScript.
Dim i%, result$, c$
For i = 1 To Len(s)
c = Mid$(s, i, 1)
If Instr(" ""#%&/:;<=>?@[]^`{|}~+", c) = 0 Then
' these are the special URL characters as identified by HTML reference books, and + which Notes uses to represent a space. If this char is not one of these, we can leave as is.
result = result & c
Else
result = result & "%" & Right$("0" & Hex(Uni(c)), 2)
End If
Next
escape = result
End Function

Function unescape(Byval s$) As String
' Given a string that contains "%" codes for spaces and other punctuation, as they would appear in a URL, this function converts them back to the original string using the Uchr$ function.
Dim pos%, lpos%, ccod$, result$
lpos = 1
pos = Instr(s, "%")
Do Until pos = 0
' the characters up until the % are ones we can just add to the string.
If pos > lpos Then result = result & Mid$(s, lpos, pos-lpos)
ccod = Mid$(s, pos+1, 2) ' get the hex code of the character
If ccod Like "[a-fA-F0-9][a-fA-F0-9]" Then
result = result & Uchr$(Cint("&H" & ccod))
lpos = pos + 3
Else
result = result & "%"
lpos = pos + 1
End If
pos = Instr(lpos, s, "%")
Loop
unescape = result & Mid$(s, lpos)
End Function

This was last published in November 2000

Dig Deeper on LotusScript

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close