I've seen a lot of posts over time relating to importing and exporting CSV. Most of the answers involve using TextReader.readline and String.split, which will not work with any but the simplest data. When you are writing for users who have the expectation that your application will work with anything they export from Excel, you will have to cover all the CSV bases.
I hope that this post will give you a clear idea of what you're involving yourself in when you decide you need to read a CSV file.
The characteristics of CSV data are:
- The comma character is used to separate the fields. (This is obvious, but I thought I'd start with a couple of obvious points to warm up)
- The last field on the line is ended by the end-of-line character or the physical end of the file.
- Any field that contains commas, double-quotes or control characters will be surrounded by double-quote marks.
- Any double-quote marks within the field will be "escaped" with an extra double-quote character. For instance, the value Paul "Chuck" Norris would be converted to "Paul ""Chuck"" Norris".
- After the opening double-quote ANY character is valid. Including line breaks. This is why you can't use readline.
I have a parser class that works nicely and I'll post that on this thread in a little while, along with some notes on using it.