Lotus Notes FAQ Visit Our Sponsor!

How do you do @Explode in LotusScript?

There is no equivalent but here is a function that performs an @Explode:

Function AtExplode(strList As String, varSeparators As Variant) As Variant

'********************************************************************************************************************
' From ebrehault@amadeus.net
' Breaks a delimited string into its component elements and returns the elements in a string array
'
' Parameters:
' Input:
' strList: The delimited string to parse
' varSeparators: An array of strings representing the delimiters used in strList
'
' Return Value: An array of strings with each element representing an element in strList
'
'********************************************************************************************************************

Dim intI, intDone As Integer 'Loop control variables
Dim intPosTemp, intPosLastDelimiter, intPosNextDelimiter As Integer 'For determining position of last found and next delimiter in strList
Dim strLastDelimiter, strNextDelimiter As String 'The actual delimiters
last found and next occuring in strList
Dim strElement As String 'An element of strList
Dim astrElement() As String 'The array to return containing the elements of strList
Dim iastrElement As Integer 'Count of elements found in strList

'If an empty string is passed in, return an empty string
If Trim$(strList) = "" Then
  Explode = ""
  Goto Explode_Exit
End If

'Initialize the variables
iastrElement = 0
strLastDelimiter = ""
strNextDelimiter = ""
intPosLastDelimiter = 1 'The combination of intPosLastDelimiter and the Length of strLastDelimiter determine where the next element should start
intDone = False
intPosNextDelimiter = Len(strList) 'The default position for the next delimiter is the end of strList

'Loop through the potential delimiters to identify the next one. Store its position in strLIst and its text
For intI = Lbound(varSeparators) To Ubound(varSeparators)
  intPosTemp = Instr(1, strList, varSeparators(intI))
  If intPosTemp <> 0 And intPosTemp <= intPosNextDelimiter Then
    intPosNextDelimiter = intPosTemp
    strNextDelimiter = varSeparators(intI)
  End If
Next

'Process strList until intDone is true
Do
  'Get the next element in strList with extraneous spaces removed. The starting position of the next element is equal to the starting position
  'of the last delimiter found + the length of the last delimiter found (intPosLastDelimiter + Len(strLastDelimiter))
  If strNextDelimiter = "" Then
    'If strNextDelimiter is blank then we're getting the rest of the string.
    strElement = Trim(Mid(strList, intPosLastDelimiter + Len(strLastDelimiter)))
  Else
    'The length of the next element equals the position of the last character of the element (intPosNextDelimiter - 1) minus the position
    'one character before the first character of the element (intPosLastDelimiter + Len(strLastDelimiter) - 1)
    strElement = Trim(Mid(strList, intPosLastDelimiter + Len(strLastDelimiter),_
     intPosNextDelimiter - 1 - (intPosLastDelimiter + Len(strLastDelimiter) - 1)))
  End If
  If strElement <> "" Then
    'If the current element isn't blank, increment the count of elements and add it to the array of elements
    iastrElement = iastrElement + 1
    Redim Preserve astrElement(1 To iastrElement)
    astrElement(iastrElement) = strElement
  End If
  If strNextDelimiter <> "" And (intPosNextDelimiter + Len(strNextDelimiter) - 1) < Len(strList) Then
    'If you haven't reached the end of strList (strNextDelimiter <> "") and the last character of the last delimiter found
    'is not at the end of strList (intPosNextDelimiter + Len(strNextDelimiter) - 1 < Len(strList)

    'Set the Last delimiter variables equal to reflect the last delimiter found
    intPosLastDelimiter = intPosNextDelimiter
    strLastDelimiter = strNextDelimiter

    'Set the Next delimiter variables to assume there isn't one
    intPosNextDelimiter = Len(strList)
    strNextDelimiter = ""

    'Loop through the potential delimiters to identify the next one. Store its position in strLIst and its text
    For intI = Lbound(varSeparators) To Ubound(varSeparators)
      'Start looking with the character in strList after the end of the last delimiter found
      intPosTemp = Instr(intPosLastDelimiter + Len(strLastDelimiter), strList, varSeparators(intI))
      If intPosTemp <> 0 And intPosTemp <= intPosNextDelimiter Then
        'If the position of the current delimiter is less than the nearest one found so far, store it's position and text
        intPosNextDelimiter = intPosTemp
        strNextDelimiter = varSeparators(intI)
      End If
    Next
  Else
    'If you've reached the end of strList (strNextDelimiter = "") or the last character of the last delimiter found
    'is at the end of strList (intPosNextDelimiter + Len(strNextDelimiter) - 1 >= Len(strList) then you're done.
    intDone = True
  End If
Loop Until intDone

'Return the array containing the elements
Explode = astrElement

Explode_Exit:

End Function


Applies to Notes Versions: 4 4.5 4.6 5.0 5
Last Modified: August 18, 1998