Results 1 to 5 of 5

Thread: Spliting

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Spliting

    How to split for example this string

    12.2.2009,21.2.2009,20.9.2019

    So, coma (,) is most important.

    So, I want to fill listbox with this strings, and split between comas.

    12.2.2009
    21.2.2009
    20.9.2019

    The number of string is not definite.

    Thanks!

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Spliting

    vb.net Code:
    1. Dim source As String = "12.2.2009,21.2.2009,20.9.2019"
    2.  
    3. Dim tokens() As String = source.Split(","c)
    4.  
    5. For Each token As String In tokens
    6.      Debug.WriteLine(token)
    7. Next

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: Spliting

    I don't understand your code very well. Where is listbox in the whole story?

  4. #4
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Spliting

    cicatrix's code is about as basic as it gets. When you use "Split()", it returns an array of strings; in the example's case "tokens()". If that last sentence confuses you, then check out MSDN for help on the basics of arrays. They're one of the oldest and most used structures in programming.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  5. #5
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: Spliting

    in the cicatrix code replace

    Code:
    For Each token As String In tokens
         Debug.WriteLine(token)
    Next
    with

    Code:
    ListBox1.Items.AddRange(tokens)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width