If you are a .Net developer, there is very little reason why you should ever write your own CSV parser. SecretGeek has a pretty good
blog post on why it is a bad idea. He mentions a library I have known about for a while called
FileHelpers. It has some pretty awesome features, such as:
- Serialization and deserialization of delimited or fixed width data
- Attribute based field conversion definition (e.g. [FieldConverter(ConverterKind.Date, "dd-MM-yyyy")] ). You can also create custom converters.
- File differences for files with the same record structure
- The ability to skip empty or first/last N records
An alternative less powerful approach is to use Microsoft's
XmlCsvReader. This is more useful if you want to treat the file like a read only XML document.