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 last published in November 2000

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close