StreamReader with tab delimited text file
asp.net, c#, csv, split, streamreader
Solution
You can try this:
DataTable table = new DataTable();
table.Columns.Add("col1");
table.Columns.Add("col2");
table.Columns.Add("col3");
var lines = File.ReadAllLines(@"Data.txt").ToList();
lines.ForEach(line => table.Rows.Add(line.Split((char)9)));
I presumed that rows are delimited by newline (if that's the case `ReadAllLines` method can be used). Number 9 is the ASCII value for horizontal tab character and it is used for splitting the line. `ForEach` is a method that can be used on generic lists, it is there instead of the `foreach` loop.
Problem
I have a similar requirement to this post... Populate Gridview at runtime using textfile Where I want to read a text file with `StreamReader` and populate a `DataTable` with the data in the file, however I'm not sure how to implement a `split()` with a tab. Could anybody point me in the right direction, please?