|
-
Jun 5th, 2006, 02:11 AM
#1
Thread Starter
Member
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.
-
Jun 5th, 2006, 02:24 AM
#2
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.
-
Jun 8th, 2006, 01:01 AM
#3
Thread Starter
Member
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.
-
Jun 8th, 2006, 01:09 AM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|