QB64 Phoenix Edition
String to Array - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3)
+---- Forum: Utilities (https://staging.qb64phoenix.com/forumdisplay.php?fid=8)
+---- Thread: String to Array (/showthread.php?tid=1470)



String to Array - AtomicSlaughter - 02-13-2023

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



RE: String to Array - mnrvovrfc - 02-13-2023

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