Lotus Notes FAQ Visit Our Sponsor!

How do you decode parameters in URLs?

Using these two functions, you can decode parameters into an array of strings that you can later parse. These two functions handle parameter characters such as spaces which had to be "escaped" to be passed as parameters.

Function unescape( thing$ ) As String

     ' From Hugh Pyle@NIP
     ' Treat thing$ as a string which came from a Web URL;
     ' un-escape it, ie: "+" becomes space, and %HH become individual characters.
     '
     Dim a$
     Dim bit$
     Dim j%
     Const hx$ = "ABCDEFabcdef1234567890"
     For j=1 To Len( thing$ )
          bit$ = Mid$( thing, j, 1 )
          If bit$="+" Then
               bit$ = " "
          Elseif bit$="%" Then
               If ( Instr( hx$, Mid$( thing, j+1, 1 ) )>0 And Instr( hx$, Mid$( thing, j+2, 1 ) )>0 ) Then
                    bit$ = Chr$( Val( "&H" & Mid$( thing, j+1, 2 ) ) )
                    j = j + 2
               End If
          End If
          a$ = a$ + bit$
     Next
     unescape = a
End Function


Function URLGetParamArray( url$, param$ ) As Variant
     ' From Hugh Pyle@NIP
     ' Find as many occurrences of "&param=" as appear in the URL, and return the value(s) as an array.
     ' Unescape the values while we're doing it.
     Dim n%, m%, c%
     Dim p As Variant
     c = 0
     Redim p( c ) As String
     n = Instr( 1, url$, "&" + param$ + "=", 5 )
     While n>0
          Redim Preserve p(c) As String
          m = Instr( n+1, url$+"&", "&")
          p(c) = unescape( Mid$( url$, n+ Len(param$) + 2, m - n - Len(param$) - 2) )
          n = Instr( m, url$, "&" + param$ + "=", 5 )
          c = c + 1
     Wend
     URLGetParamArray = p
End Function


Applies to Notes Versions: 4 4.5 4.6 5
Last Modified: September 8, 1999