Question

How do we do a URL decode on a text recieved from request in an IBM Domino lotusscript agent?

Was it helpful?

Solution

Unfortunately there is no default URLdecode- function in LotusScript. I always use Evaluate for this:

Dim varResult as Variant
Dim strUrl as String
Dim strUrlDecoded as String

strUrl = "Employee%2FMy%20Database.nsf"
varResult = Evaluate( {@URLDecode( "Domino"; "} & strUrl & {" )} )
strUrlDecoded = varResult( 0 )

OTHER TIPS

Some easy googling shows several implementations such as this one:

Function URLDecode(inpString As String) As String
   Dim temp As String
   Dim hexValue As String
   Dim ch As String
   Dim pos As Integer
   Dim newPos As Integer
   ' First, replace any plus signs with spaces
   temp = inpString
   While Instr(temp, "+") <> 0
      temp = Left(temp, Instr(temp, "+")-1) & " " & Mid(temp, Instr(temp, "+")+1)
   Wend
   ' Next, replace any "%x" encodings with the character
   pos = 1
   While Instr(pos, temp, "%x") <> 0
      hexValue = Mid(temp, Instr(pos, temp, "%x")+2, 2)
      ch = Chr$(Val("&H" & hexValue))
      newPos = Instr(pos, temp, "%x")+2
      temp = Left(temp, Instr(pos, temp, "%x")-1) & ch & Mid(temp, Instr(pos, temp, "%x")+4)
      pos = newPos
   Wend   
   ' Next, replace any "%u" encodings with the Unicode character
   pos = 1
   While Instr(pos, temp, "%u") <> 0
      hexValue = Mid(temp, Instr(pos, temp, "%u")+2, 4)    ' Unicode encodings are 4 hex characters
      ch = Uchr$(Val("&H" & hexValue))
      newPos = Instr(pos, temp, "%u")+2    ' Skip over so we don't find "%" if that's what it was decoded to
      temp = Left(temp, Instr(pos, temp, "%u")-1) & ch & Mid(temp, Instr(pos, temp, "%u")+6)
      pos = newPos
   Wend
   ' Next, replace any "%" encodings with the character
   pos = 1
   While Instr(pos, temp, "%") <> 0
      hexValue = Mid(temp, Instr(pos, temp, "%")+1, 2)
      ch = Chr$(Val("&H" & hexValue))
      newPos = Instr(pos, temp, "%")+1
      temp = Left(temp, Instr(pos, temp, "%")-1) & ch & Mid(temp, Instr(pos, temp, "%")+3)
      pos = newPos
   Wend
   URLDecode = temp
End Function

Source: http://www.breakingpar.com/bkp/home.nsf/0/830B9F6BB4A899AB87256AFB0014A04A

If the agent can see the 'CGI' fields (on the documentContext) then use the 'QUERY_STRING_DECODED' field, which will contain the query-string, decoded!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top