Tag Archives: csv file

C# || How To Parse A Delimited CSV File Using C#

The following is a module with functions which demonstrates how to parse a delimited CSV file using VB.NET.

This function parses a CSV file and returns its results as a List. Each List index represents a line in the CSV file, with each item in the list representing a record contained on that line.

The function demonstrated on this page uses FileIO.TextFieldParser to parse values in a CSV file.

Note: To use the function in this module, make sure you have a reference to ‘Microsoft.VisualBasic‘ in your project.

One way to do this is, in your Solution Explorer (where all the files are shown with your project), right click the ‘References‘ folder, click ‘Add Reference‘, then type ‘Microsoft.VisualBasic‘ in the search box, and add the reference titled Microsoft.VisualBasic in the results Tab.


1. Parse CSV File

The example below demonstrates the use of ‘Utils.Methods.ParseCsv‘ to parse a CSV file and return its results as a List.

The optional function parameter allows you to specify the delimiters. Default delimiter is a comma (,).

Sample CSV used in this example is the following:


2. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


3. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

VB.NET || How To Parse A Delimited CSV File Using VB.NET

The following is a module with functions which demonstrates how to parse a delimited CSV file using VB.NET.

The function demonstrated on this page uses FileIO.TextFieldParser to parse values in a CSV file.

This function parses a CSV file and returns its results as a List. Each List index represents a line in the CSV file, with each item in the list representing a record contained on that line.


1. Parse CSV File

The example below demonstrates the use of ‘Utils.ParseCsv‘ to parse a CSV file and return its results as a List.

The optional function parameter allows you to specify the delimiters. Default delimiter is a comma (,).

Sample CSV used in this example is the following:


2. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


3. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.