C# Substring for CSV files

Pwit used Ask the Experts™
Hi all,

I am trying to parse a CSV file by the commas.  I would initially get a index of a comma and everything that and the next comma.  It returns what looks like the correct indices, but when I apply it to the code it outputs something entirely different.  Is there something special that has to be done when parsing CSV files?  Thanks in advance.

Here's a sample of what I am trying to read from the CSV file:

"Internet",278766,"98385512","05/01/2009","Exchange, Expert","eRes-Plus - 2022609583","R8",78,7.80," "," ",7.80,""

My goal is to extract just "Exchange, Expert" from the string, but instead I get:

Exchange, Expert","eRes-Plus - 3127554506","R8",105,10.50," "


Here is the code I am trying to use with the index positions already counted out by hand to make sure its right:
text = "Internet",278766,"98385512","05/01/2009","Exchange, Expert","eRes-Plus - 2022609583","R8",78,7.80," "," ",7.80,""

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
substring function arguments are "start, length" and not "start, end"

MessageBox.Show(text.Substring(47,62 - 47 + 1));


Sorry this is the String that I have entered in the code:

String text = "\"Perkins & Will\",278766,\"98385512\",\"05/01/2009\",\"Clinch, Paul\",\"eRes-Plus - 2022609583\",\"R8\",78,7.80,\" \",\" \",7.80,\"\""

Open in new window


Thanks angelll, that was the trick.  For some reason I must have been thinking about the Java substring method or something else.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial