posted on Friday, April 09, 2004 9:20 AM
by
taylorza
Parsing CSV files into DataTable with RegEx
Just sitting blindly surfing, I came across a routine that appears to do a good job of using RegEx to parse CSV files and build a DataTable. It needs some enhancing to switch between generated columns and using the first row as column headers, also requires some changes to be able to handle very large files, but it seems to be a good starting point. Here is the RegEx used
((?<field>[^\",\\r\\n]+)|\"(?<field>([^\"]|\"\")+)\")(,|(?<rowbreak>\\r\\n|\\n|$))
It needs some post processing for the double quoted identifiers, but for the details take a look at the original link
http://www.hotblue.com/article0000.aspx?a=0006