Read read pipe delimited text file in C#

What is the best way to read Read read pipe delimited text file in C# ?

Solution

Read pipe delimited text file in C#

var file = @"path_to_your_file";
var parser = new TextFieldParser(file);
var dt = new DataTable();
parser.SetDelimiters("|");
while(!parser.EndOfData)
{
    var currentRow = parser.ReadFields();
    if(headerRow)
    {
        foreach(var field in currentRow)
        {
            dt.Columns.Add(field, typeof(object));
        }
            headerRow = false;
    }
    else
    {
        dt.Rows.Add(currentRow);<

More Questions