Parsing Tab delimited text files

后端 未结 5 740
长发绾君心
长发绾君心 2020-12-10 19:07

I have a tab delimited file with some columns and rows for example: some rows might not have value for some columns. What we know is that the \"order\" doe

5条回答
  •  不知归路
    2020-12-10 19:58

    You can use File.ReadLines() method (if you are using .NET Framework Version 4.0 or above) without any performance penalty as it would not load whole file content into Memory.

    Try This:

    using System.IO;
    
    class FileData
    {
    public string Column2{ get; set; }
    public string Column12{ get; set; }
    public string Column45{ get; set; }
    }
    
    
    List filedata =  new List();
    
     FileData temp = new FileData();
     foreach(var line in File.ReadLines("filepath.txt").Skip(1))
     {     
       var tempLine = line.Split('\t');
       temp.Column2 = tempLine[1];
       temp.Column12 = tempLine[11];
       temp.Column45 = tempLine[44]; 
       filedata.Add(temp);
     }
    

提交回复
热议问题