Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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


Possibly Related Threads…
Thread Author Replies Views Last Post
  STRING$ empowered with StringPatternFilling TempodiBasic 6 1,204 05-09-2025, 06:00 PM
Last Post: TempodiBasic
  Split String to Array Using Strtok (Attempt #2) SpriggsySpriggs 0 529 12-17-2024, 06:37 PM
Last Post: SpriggsySpriggs
  PrintW - print a long string, breaking it at the last space or hyphen before col. 79 TDarcos 21 4,004 04-22-2024, 09:52 PM
Last Post: Pete
  Fonts from String Patterns bplus 15 3,670 08-30-2023, 03:01 PM
Last Post: grymmjack
  Remove Spaces (or other characters) from a String George McGinn 10 2,901 12-31-2022, 12:21 PM
Last Post: euklides

Forum Jump:


Users browsing this thread: 1 Guest(s)