logo

New Response

« Return to the main article

You are replying to:

  1. (second try for better formatting)

    The GetFieldValue method had a bug in it that I corrected below. That's the problem with trying to post my code immediately after I start to use it a little.

    [<br clear="all"><code class="LotusScript">Public Class RequestContentParser<br> &nbsp;Private psRC As String<br> &nbsp;Private piAmpPos As Integer<br> &nbsp;<br> &nbsp;Sub new(Byval sRequest_Content As String)<br> &nbsp;&nbsp;psRC = sRequest_Content<br> &nbsp;&nbsp;piAmpPos = 0<br> &nbsp;End Sub<br> &nbsp;<br> &nbsp;Private Function Unescape(Byval s As String) As String<br> &nbsp;&nbsp;Dim iPercent As Integer<br> &nbsp;&nbsp;Dim iPlus As Integer<br> &nbsp;&nbsp;Dim sL As String<br> &nbsp;&nbsp;Dim sM As String<br> &nbsp;&nbsp;Dim sR As String<br> &nbsp;&nbsp;<br> &nbsp;&nbsp;iPercent = Instr(s,"%")<br> &nbsp;&nbsp;iPlus = Instr(s,"+")<br> &nbsp;&nbsp;If iPlus < iPercent And iPlus <> 0 Then<br> &nbsp;&nbsp;&nbsp;sL = Left$(s, iPlus - 1)<br> &nbsp;&nbsp;&nbsp;sR = Mid$(s, iPlus + 1)<br> &nbsp;&nbsp;&nbsp;Unescape = sL + " " + Unescape(sR)<br> &nbsp;&nbsp;Elseif iPercent <> 0 Then<br> &nbsp;&nbsp;&nbsp;sL = Left$(s,iPercent-1)<br> &nbsp;&nbsp;&nbsp;sM = Mid$(s,iPercent+1,2)<br> &nbsp;&nbsp;&nbsp;sR = Mid$(s, iPercent+3)<br> &nbsp;&nbsp;&nbsp;Unescape = sL + Chr$(Cint("&h" & sM)) + Unescape(sR)<br> &nbsp;&nbsp;Else<br> &nbsp;&nbsp;&nbsp;Unescape = s<br> &nbsp;&nbsp;End If<br> &nbsp;End Function<br> &nbsp;<br> &nbsp;Public Function GetNextField(sFieldName As String, sValue As String) As Variant 'boolean, true if successful, false if no more fields<br> &nbsp;&nbsp;Dim iEqPos As Integer<br> &nbsp;&nbsp;Dim iFieldPos As Integer<br> &nbsp;&nbsp;<br> &nbsp;&nbsp;On Error 1 Goto ErrorSub<br> &nbsp;&nbsp;If piAmpPos = -1 Then Error 1<br> &nbsp;&nbsp;iFieldPos = piAmpPos + 1<br> &nbsp;&nbsp;iEqPos = Instr(iFieldPos, psRC, "=")<br> &nbsp;&nbsp;If iEqPos = 0 Then Error 1<br> &nbsp;&nbsp;sFieldName = Mid(psRC, iFieldPos, iEqPos - iFieldPos)<br> &nbsp;&nbsp;piAmpPos = Instr(iEqPos, psRC, "&")<br> &nbsp;&nbsp;If piAmpPos <> 0 Then<br> &nbsp;&nbsp;&nbsp;sValue = Unescape(Mid(psRC, iEqPos + 1, piAmpPos - iEqPos - 1))<br> &nbsp;&nbsp;Else<br> &nbsp;&nbsp;&nbsp;sValue = Unescape(Mid(psRC, iEqPos + 1))<br> &nbsp;&nbsp;&nbsp;piAmpPos = -1 'flag that there are no more fields<br> &nbsp;&nbsp;End If<br> &nbsp;&nbsp;GetNextField = True<br> ExitSub:<br> &nbsp;&nbsp;Exit Function<br> ErrorSub:<br> &nbsp;&nbsp;GetNextField = False<br> &nbsp;&nbsp;Resume ExitSub<br> &nbsp;End Function<br> &nbsp;<br> &nbsp;Public Function GetFieldValue(sFieldName As String) As String<br> &nbsp;&nbsp;Dim iAmpPos As Integer<br> &nbsp;&nbsp;Dim iFieldPos As Integer<br> &nbsp;&nbsp;Dim iValPos As Integer<br> &nbsp;&nbsp;Dim sValue As String<br> &nbsp;&nbsp;<br> &nbsp;&nbsp;iFieldPos = Instr("&" + psRC, "&" + sFieldName + "=")<br> &nbsp;&nbsp;If iFieldPos = 0 Then<br> &nbsp;&nbsp;&nbsp;GetFieldValue = ""<br> &nbsp;&nbsp;Else<br> &nbsp;&nbsp;&nbsp;iValPos = iFieldPos + 1 + Len(sFieldName)<br> &nbsp;&nbsp;&nbsp;iAmpPos = Instr(iValPos, psRC, "&")<br> &nbsp;&nbsp;&nbsp;If iAmpPos = iValPos Then<br> &nbsp;&nbsp;&nbsp;&nbsp;GetFieldValue = ""<br> &nbsp;&nbsp;&nbsp;Else<br> &nbsp;&nbsp;&nbsp;&nbsp;GetFieldValue = Unescape(Mid(psRC, iValPos, iAmpPos - iValPos))<br> &nbsp;&nbsp;&nbsp;End If<br> &nbsp;&nbsp;End If<br> &nbsp;End Function<br> End Class</code>]

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment: