Splitting a string

Posts 1–3 of 3 · Page 1 of 1
Splitting a string
What would be the best way of splitting all this into separate outputs in a simpler way than splitting and then splitting strings?

Code:
194890,1884,123499116 120785,99,13187853 94656,99,13291667 132128,99,13574061 123114,99,14096784 245129,83,2731112 331952,63,374513 433058,75,1255007 124083,99,13104044 117635,99,13043183 158826,89,5251023 42331,99,13610532 208665,80,2089413 338981,62,351332 355150,60,293124 146580,79,1825943 330656,52,129224 245604,65,477958 313276,59,249926 313112,61,315748 231903,60,286174 489740,45,65985 30598,99,13036343 200576,69,711159 438673,39,33795 317347,51,113213 -1,-1 -1,-1 -1,-1 42303,2265 -1,-1 54086,1351 -1,-1 77671,867 37000,2104 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1
All I can think of is splitting the ",".
That'll give me,

Code:
194890
1884
123499116 120785
99
13187853 94656
99
13291667 132128
99
13574061 123114
99
14096784 245129
Then, the lines that are in bold are 2 outputs that I need to split as well. I can think of a way to do that, but that requires splitting a split string which is more coding for me.

I just wanting to know if there is a lazier way of doing this. If not, I have to prepare for some days of splitting and putting them with the corresponding skill/category.
If you were planning to put it in a textbox then that's very easy.
You just need to replace the splitter character to vbCrLf.

Code:
    Public Function Split(ByVal Text As String, ByVal Separator As String) As String
        Return Text.Replace(Separator, vbCrLf)
    End Function

    'Usage: RichTextBox.Text = Split("<<Content>>","<<Separator>>")
Or if you're planning it to use on a listbox, then this can be it.
The same method but needs to gather them into a collection
Code:
    Public Function Split2(ByVal Text As String, ByVal Separator As String) As Collection
        Dim Temp As New RichTextBox With {.Text = Text.Replace(Separator, vbCrLf)}
        Dim Result As New Collection
        For Each Line As String In Temp.Lines
            Result.Add(Line)
        Next
        Return Result
    End Function

    'Usage: ListBox1.Items.AddRange(Split2("<<Contents>>","Separator"))
Regex would be the best solution for you for sure.

VB.NET Regex.Match Function

Has some basic examples, all you need is to read on Regex formulas and then apply them into VB (There is no difference)
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us