Manage Learn to apply best practices and optimize your operations.

Converting A String Into An Array

A LotusScript function similar to @Explode() which takes a string and turns it
into an array based of off the specified item delimiter.

Example usage:
Dim avarNew As Variant

Dim strSource As String

strSource = "Item 1, Item 2, Item 3"

avarNew = split(strSource, ",")

Print avarNew(0) ' Output: Item 1
Print avarNew(1) ' Output: Item 2
Print avarNew(2) ' Output: Item 3
Function split(strSource As String, strItemDelim As String) As Variant
'****************************
' split() Function
' Copyright 1998-99 GWI Software, Inc.
' Created By Jordan Matthiesen
'
' Splits a source string into an array
' using the item delimiter specified.
'
'Parameters:
' strSource The source, "flat", string to be split
' strItemDelim The item delimiter to use
'
'Returns:
' Variant An array containing the split string
'****************************

'*** Variable Declarations ***
Dim astrReturn() As String ' The array to return

Dim intElement As Integer ' The array element currently being
set
Dim z_intItemCount As Integer ' The total number of elements for
the array
Dim z_intStartOfItem As Integer ' The start position of the item in
the
' source string.
Dim z_intEndOfItem As Integer ' The end position of the item in the
source
' string.

Dim z_strCurItem As String ' The currently parsed item
Dim z_strRemaining As String ' The remaining string to cycle
through
Dim z_strStartOfItemBack As String ' The rest of the string, from the
start of
' the item on back.
'*** End Variable Declarations ***

' Put the source string into a holder:
z_strRemaining = strSource

' Cycle through the source string and get a
' count of elements:
While (Not z_strRemaining = "")
z_intStartOfItem = Instr(1, z_strRemaining, strItemDelim)

If (z_intStartOfItem <> 0) Then
z_intItemCount = z_intItemCount + 1
z_strRemaining = Mid(z_strRemaining, z_intStartOfItem +
Len(strItemDelim), _
Len(z_strRemaining))
Else
z_intItemCount = z_intItemCount + 1
z_strRemaining = ""
End If
Wend

' Size the return array so that it can hold
' all of the elements:
Redim astrReturn(z_intItemCount - 1)

' Reset the holder to the value of the source string:
z_strRemaining = strSource

' Cycle through the source list, parsing the
' string into individual array elements:
While (Not z_strRemaining = "")
For intElement = 0 To Ubound(astrReturn)
' Find the end of the current element:
z_intEndOfItem = Instr(1, z_strRemaining, strItemDelim)

' If there is still an item delimiter in the string, parse
' out the item, otherwise assume the remaining text is the
' last item:
If (z_intEndOfItem <> 0) Then
z_strCurItem = Mid(z_strRemaining, 1, z_intEndOfItem - 1)
astrReturn(intElement) = z_strCurItem
z_strRemaining = Mid(z_strRemaining, z_intEndOfItem +
Len(strItemDelim), _
Len(z_strRemaining))
Else
astrReturn(intElement) = z_strRemaining
z_strRemaining = ""
End If

Next
Wend

' Return the split array to the caller:
split = astrReturn
End Function

Dig Deeper on Domino Resources - Part 3

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