Skip to content

Instantly share code, notes, and snippets.

@bitsprint
Created September 16, 2013 13:02
Show Gist options
  • Save bitsprint/6580414 to your computer and use it in GitHub Desktop.
Save bitsprint/6580414 to your computer and use it in GitHub Desktop.
Csv Parser
using (Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser("C:\\testfile.txt")) {
parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
parser.SetDelimiters(",");
string[] currentRow = null;
while (!parser.EndOfData) {
try {
currentRow = parser.ReadFields();
string currentField = null;
foreach (string field in currentRow) {
currentField = field;
Interaction.MsgBox(currentField);
}
} catch (Microsoft.VisualBasic.FileIO.MalformedLineException ex) {
Interaction.MsgBox("Line " + ex.Message + "is not valid and will be skipped.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment