Results 1 to 4 of 4

Thread: How to use CommaDelimitedStringCollection class

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    44

    How to use CommaDelimitedStringCollection class

    Hi,

    I want to read a comma delimited file, but sometimes the data is enclosed with double quote, sometimes not, so I can't just use the function split. I've looked around and found this class CommaDelimitedStringCollection in .NET framework (version 2.0). How can I use this class?
    CommaDelimitedStringCollection myVar; didn't work, it just keeps saying that it cannot find the type or namespace (I've used System.Configuration, System.Collections, and System.Collections.Specialized).

    Thanks in advance.

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

    Re: How to use CommaDelimitedStringCollection class

    That class is a member of the System.Configuration namespace and is not intended for reading CSV files. It is one of the classes that enables you to interact with config files. If you want to read a CSV file then just split the line and then test each element to see if it starts and ends with a double quote and, if so, remove them. You could quite easily wrap this in your own class that you can then use anywhere you like.
    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

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    44

    Re: How to use CommaDelimitedStringCollection class

    Thanks for clearing that up. So there's no built-in function/class to read csv files in .NET? I used to code with Borland C++ and I've used a function (I think it's from the string class) that reads and writes csv easily (not as a file, but as a string) - I can't remember the function name, have to shift through the archive to find the source code.

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

    Re: How to use CommaDelimitedStringCollection class

    As I said, writing your own methods to read and write CSV files is not too hard. String.Split and String.Join are your friends in this regard. .NET 2.0 also adds some new I/O methods, like IO.File.ReadAllLines so you can read the lines of a text file into a string array in one line of code.
    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

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