Showing posts from September, 2008

Parse CSV or other separated strings

I had to work with Comma Separated Values (CSV) files the last few days and updated some code to make it easier to use with LINQ. Quick review, a CSV file is a file that has all of the values separated by a comma. Values that contain a comma are typically qualified with double quotes. For example: Abraham, Lincoln, 03/4/1861, 04/15/1865, "Republican, National Union" Basically, I created a class called SeparatedString that performs all the functionality of parsing the data so that I can retrieve it later. When the Text property is set it figures out the location of all relevant commas and loads them into a List. The GetValue method then uses the index to grab the occurrence of the comma that precedes the value to be retrieved. Public Class SeparatedString ''' <summary> ''' Contains the position of all separator characters in the string ''' </summary> ''' <remarks></remarks>