C# How to skip number of lines while reading text file using Stream Reader?

前端 未结 6 1313
天命终不由人
天命终不由人 2020-12-05 18:50

I have a program which reads a text file and processes it to be seperated into sections.

So the question is how can the program be changed to allow the program to sk

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 19:13

    I'd guess it's as simple as:

        static void Main(string[] args)
        {
            var tr = new StreamReader(@"C:\new.txt");
    
            var SplitBy = "----------------------------------------";
    
            // Skip first 5 lines of the text file?
            foreach (var i in Enumerable.Range(1, 5)) tr.ReadLine();
            var fullLog = tr.ReadToEnd(); 
    
            String[] sections = fullLog.Split(new string[] { SplitBy }, StringSplitOptions.None);
    
            //String[] lines = sections.Skip(5).ToArray();
    
            foreach (String r in sections)
            {
                Console.WriteLine(r);
                Console.WriteLine("============================================================");
            }
        }
    

提交回复
热议问题