Separating String Into Pieces, Delimited By A Separator Char

This one is for developers who use and abbuse of Query_String parameter when
running web agents. Of course, there are lots of other applications for this
function, but the reason i wrote was mainly web agents.
The moral:
-> piece ("piece1^piece2^piece3", "^", 1) returns "piece1"
-> piece ("piece1^piece2^piece3", "^", 2) returns "piece2"
-> piece ("piece1^piece2^piece3", "^", 3) returns "piece3"
...and so on...
Parameters:
#1: the whole string
#2: the separator of "pieces"
#3: number of the piece you want
Function Piece (wholestring As String, separator As String, position As
Integer) As String

Dim size As Integer
Dim i As Integer
Dim piece_current As Integer
Dim begin_piece As Integer
Dim end_piece As Integer
Dim return_value As String
Dim char As String

size = Len (wholestring)
piece_current = 1
begin_piece = 1
end_piece = 1

For i = 1 To size
char = Mid (wholestring, i, 1)

If char = separator Then
If piece_current = position Then 'Found piece
end_piece = i - 1
Exit For
Else
piece_current = piece_current + 1
begin_piece = i + 1
End If
End If
Next

If end_piece = 1 Then 'There's only one piece
end_piece = size
End If

return_value = Mid (wholestring, begin_piece, (end_piece - begin_piece +
1))
piece = return_value

End Function




Example: in web agents...

querystring = doc.query_string(0)

'First argument
first = piece (piece (Querystring, "&", 2), "=", 2)

'Second argument
second = piece (piece (Querystring, "&", 3), "=", 2)

'Third argument
third = piece (piece (Querystring, "&", 4), "=", 2)

...and so on.

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

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 ...

SearchDataCenter

SearchContentManagement

Close