How to parse a text file with C#

后端 未结 7 1910
面向向阳花
面向向阳花 2020-12-08 14:57

By text formatting I meant something more complicated.

At first I began manually adding the 5000 lines from the text file I\'m asking this question for,into my proje

7条回答
  •  隐瞒了意图╮
    2020-12-08 15:12

    You could do something like:

    using (TextReader rdr = OpenYourFile()) {
        string line;
        while ((line = rdr.ReadLine()) != null) {
            string[] fields = line.Split('\t'); // THIS LINE DOES THE MAGIC
            int theInt = Convert.ToInt32(fields[1]);
        }
    }
    

    The reason you didn't find relevant result when searching for 'formatting' is that the operation you are performing is called 'parsing'.

提交回复
热议问题