Manage Learn to apply best practices and optimize your operations.

String Functions

Implode, Explode & Replace Substring

Option Public

Function Explode(inputString As String, delimiter As String) As Variant

Dim workingString As String
workingString = inputString

Dim array() As String
Redim array(0)

Dim pos As Integer
Dim nextPos As Integer
pos = Instr(workingString, delimiter)
While pos <> 0
array(Ubound(array)) = Left(workingString, pos - 1)
workingString = Right(workingString, Len(workingString) -
Len(delimiter) - pos + 1)
pos = Instr(workingString, delimiter)
Redim Preserve array(Ubound(array) + 1)
array(Ubound(array)) = workingString

Explode = array

End Function

Function Implode(inputArray As Variant, delimiter As String) As String

If Datatype(inputArray) = 8 Then
Implode = inputArray
Exit Function
End If

Forall strInput In inputArray
Implode = Implode + strInput + delimiter
End Forall

Implode = Left(Implode, Len(Implode) - Len(delimiter))

End Function

Function ReplaceSubstring(Byval strSource As String, strFind As String,
strReplace As String) As String

' ThisFunction searches the string passed in strSource for all
' occurences of the string passed in strFind. It then replaces
' the strFind with the specified strReplace. If an error occurs,
' a NULL value is returned ("").

On Error Goto TheEnd

Dim begin As Integer
Dim found As Integer
Dim strReplaceSource As String
begin = 1

If Strcompare(strFind, "") = 0 Or Strcompare(strSource, "") = 0 Then Goto

found = Instr(begin, strSource, strFind, 1)
While (found > 0)
begin = found + Len(strFind)
strReplaceSource = Left$(strSource, (found - 1)) & strReplace & _
Right$(strSource, Len(strSource) - (found + (Len(strFind) - 1)))
strSource = strReplaceSource
found = Instr(begin, strSource, strFind, 1)

ReplaceSubstring = strSource
Exit Function

ReplaceSubstring = ""

End Function
Sub Initialize

End Sub

Dig Deeper on Domino Resources - Part 8

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials'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 ...