Link to home
Start Free TrialLog in
Avatar of Pwit
Pwit

asked on

C# Substring for CSV files

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," "

pwit

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,""
 
MessageBox.Show(text.Substring(47,62));

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pwit
Pwit

ASKER

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

Avatar of Pwit

ASKER

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