|
|
Title | Make a function to split a string into an array of strings by using multiple separators in Visual Basic 6. |
Description | This example shows how to make a function to split a string into an array of strings by using multiple separators in Visual Basic 6. |
Keywords | split, string, separators |
Categories | Strings |
|
|
Thanks to Mariusz S.
Function SplitEx finds the first separator in its parameter array. It then loops through the other separators, replacing them with the first one. Finally it uses Split to split the string into an array using just the first separator.
|
|
Function SplitEx(ByVal s As String, ParamArray separators() _
As Variant) As String()
Dim sep As String
Dim i As Integer
sep = separators(LBound(separators))
'function logic: replaces different separators with one
' set at t(lbound(t))
For i = LBound(separators) + 1 To UBound(separators)
s = Replace(s, separators(i), sep)
Next i
'finally internally calls default VB Split function
SplitEx = Split(s, sep)
End Function
|
|
|
|
|
|