String Functions

Implode, Explode & Replace Substring
'String_Functions:

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)
Wend
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
TheEnd

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)
Wend

ReplaceSubstring = strSource
Exit Function

TheEnd:
ReplaceSubstring = ""

End Function
Sub Initialize

End Sub
This was first published in November 2000
This Content Component encountered an error

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWinIT

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

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close