Created
September 16, 2013 13:02
-
-
Save bitsprint/6580414 to your computer and use it in GitHub Desktop.
Csv Parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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