Read text data from file using LINQ

前端 未结 3 733
小蘑菇
小蘑菇 2021-02-03 16:24

I have following text file:

37 44 60
67 15 94
45 02 44

How to read all numbers from this file and save them into two-dimensional array, using L

3条回答
  •  太阳男子
    2021-02-03 16:58

    Do you mean something like this?

    StreamReader sr = new StreamReader("./files/someFile.txt");
    
          var t1 =
            from line in sr.Lines()
            let items = line.Split(' ')
            where ! line.StartsWith("#")
            select String.Format("{0}{1}{2}",
                items[1],
                items[2],
                items[3]);
    

    Take a look to this web: LINK

提交回复
热议问题