String to Array
#1
A Handy piece of code that will split a string into an array.

Code: (Select All)
Sub StringSplitter (ST As String, AR() As String, DL As String)
    Dim Delim(Len(DL)) As String
    For i = 1 To Len(DL)
        Delim(i) = Mid$(DL, i, 1)
    Next
    c = 1
    Do
        For i = 1 To UBound(Delim)
            If Mid$(ST, c, 1) = Delim(i) Then
                ReDim _Preserve AR(UBound(AR) + 1)
                c = c + 1
                Exit For
            End If
        Next i
        AR(UBound(AR)) = AR(UBound(AR)) + Mid$(ST, c, 1)
        c = c + 1
    Loop Until c > Len(ST)
End Sub
Reply
#2
Nice routine but why need an array at all for delimeters?

Could replace

Code: (Select All)
If Mid$(ST, c, 1) = Delim(i) Then

with

Code: (Select All)
If Mid$(ST, c, 1) = Mid$(DL, i, 1) Then

Your way would be better if the "delimeter" is allowed to be more than one character. Smile
Reply




Users browsing this thread: 1 Guest(s)