The simplest way to parse csv files. I am using external library that does the magic for you. Csv file should be separated by commas and strings with double quotes.
Download "A Fast CSV Reader":At first you have to import the external library. It's called A Fast CSV Reader, made by Sebastien Lorion. Download binaries from codeproject.com. It's shown there as well how to use it. I am going to show my example, maybe its more straight forward.
Add "A Fast CSV Reader" to your project:Your project, there are References. You can see them from Solution Explorer. Just add reference and from Browse tab select you downloaded dll file. Also add it with the using statement.
Source code viewer
- using LumenWorks.Framework.IO.Csv;Programming Language: C#
Using "A Fast CSV Reader":
Now you have a list that includes your csv file.Source code viewer
- List<string> product_codes = new List<string>();
- int fieldCount = csv.FieldCount;
- string headers = csv.GetFieldHeaders();
- while (csv.ReadNextRecord())
- for (int i = 0; i < fieldCount; i++)
- }Programming Language: C#