tags:

views:

27

answers:

2

So Im reading a csv file and splitting the string with "," as the deliminator

but some of them have quotes as to not split the specific field because it has a comma in it.

1530,Pasadena CA,"2008, 05/01","2005, 12/14"

with just comma it would be:

1530 Pasadena CA "2008 05/01" "2005 12/14"

I need it to take commas into consideration when splitting so its like this

1530 Pasadena CA "2008 05/01" "2005 12/14"

A: 

Take a look at this page for a library that offers quick and easy CSV reading.

Gabriel McAdams
Trying not to use an external library, I was thinking something like
strLine = strLine.Replace("\\"", "\'\'");
so replace "" with '' then replace , with " then replace "" with , eliminating the quotes but keeping the commas
If you just remove the quotes, then you're altering the CSV. You could end up reading it incorrectly. There are a lot of things to be careful with, regarding CSVs. I would look at the library. There's nothing wrong with using it. Its using the MIT license, so its not a problem to include it in your deployment.
Gabriel McAdams
A: 

While it still may be a new reference, there is a class within the Visual Basic assemblies that should handle this well. At least then you know it's a part of the framework. You can find details here: http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.textfieldparser.aspx

mklinker