Results 1 to 7 of 7

Thread: [RESOLVED] String split

  1. #1

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Resolved [RESOLVED] String split

    Howdy all,

    In VB6 I wrote a function to split a string by a character, which ignored quotes.

    For example, the Split functions in VB6 and C# would split the following string:

    He said, "Hello, my name is blahblah!", to everyone.

    VB6 and C# will split this like so, using a comma as the split character:

    1) He said
    2) "Hello
    3) my name is blahblah!"
    4) to everyone.

    What my function did was split it like so:

    1) He said
    2) "Hello, my name is blahblah!"
    3) to everyone.

    I'm having trouble porting it to C#. Obviously, it returned a string array, but in VB I had the comfort of using ReDim. Can anyone write me a function to split by character but ignore quotes? My brain just doesn't want to work today :/

    Cheers for any help,

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  2. #2
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502

    Re: String split

    The String class has a Replace and Split function. Those will help you !
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: String split

    .NET 2.0 provides the Array.Resize method, which does for every .NET language what VB's ReDim Preserve did just for VB.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502

    Re: String split

    Quote Originally Posted by BramVandenbon
    The String class has a Replace and Split function. Those will help you !
    Yeah I just realized I didn't read your question good enough, sorry
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

  5. #5

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: String split

    Quote Originally Posted by jmcilhinney
    .NET 2.0 provides the Array.Resize method, which does for every .NET language what VB's ReDim Preserve did just for VB.
    Hmm. I really should re-lookup most of the stuff. I haven't used .NET in a long long time..

    Thanks for the help, I ended up just looping through and storing them in an ArrayList, then copying that to a string array.

    I'll lookup that Resize stuff jmc...cheers.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] String split

    Don't use ArrayLists in .NET 2.0. If you want a collection of String objects then use a StringCollection, which was available in .NET 1.x too, or a List(Of String). Only use an ArrayList on the rare occasion that you want to be able to store multiple, unrelated types in the same collection.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: [RESOLVED] String split

    Quote Originally Posted by jmcilhinney
    Don't use ArrayLists in .NET 2.0. If you want a collection of String objects then use a StringCollection, which was available in .NET 1.x too, or a List(Of String). Only use an ArrayList on the rare occasion that you want to be able to store multiple, unrelated types in the same collection.
    I am actually looking to store different types in there aswell, but thanks for the advice

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

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