Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# .NET StreamWriter: How to skip lines when writing file using StreamWriter?

I read in a text file using StreamReader. I want to write out this same text file EXCEPT its first 4 lines and its last 6 lines.

How do I do this? Thanks.

like image 515
user776676 Avatar asked Sep 18 '25 22:09

user776676


1 Answers

string[] fileLines = File.ReadAllLines(@"your file path"); 

var result = fileLines.Skip(4).Take(fileLines.Length - (4 + 6));

File.WriteAllLines(@"your output file path", result);
like image 173
Jalal Said Avatar answered Sep 21 '25 12:09

Jalal Said