Results 1 to 3 of 3
  1. #1
    DawgiiStylz's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    Dawg House
    Posts
    7,811
    Reputation
    219
    Thanks
    2,896
    My Mood
    Tired

    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.
    Last edited by DawgiiStylz; 09-29-2012 at 10:25 AM.

  2. #2
    .Yuzuru's Avatar
    Join Date
    May 2012
    Gender
    male
    Location
    Afterlife
    Posts
    12
    Reputation
    10
    Thanks
    1
    My Mood
    Bored
    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"))
    Last edited by .Yuzuru; 10-01-2012 at 01:29 AM.

  3. #3
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    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)
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

Similar Threads

  1. [Solved] Splitting Strings
    By DawgiiStylz in forum Visual Basic Programming
    Replies: 7
    Last Post: 09-12-2012, 08:38 AM
  2. [Solved] String Splitting
    By gamernuub in forum Visual Basic Programming
    Replies: 5
    Last Post: 04-13-2012, 05:47 PM
  3. [Help] Splitting strings. [solved]
    By sythe179 in forum Visual Basic Programming
    Replies: 12
    Last Post: 04-06-2011, 03:15 AM
  4. Delphi 7 for replacing detected CE strings??
    By jokuvaan11 in forum WarRock - International Hacks
    Replies: 5
    Last Post: 07-02-2007, 03:34 AM
  5. String Theory
    By arunforce in forum General
    Replies: 8
    Last Post: 01-14-2007, 09:49 AM