Reputation: 130
How can I remove everything from a text file except for the first line?
I tried:
var lines = File.ReadAllLines(path + "/resource.rpf" + "/" + "__resource.lua");
foreach (var item in lines.Take(1));
but doesn't work like I wanted.
Upvotes: 1
Views: 1060
Reputation: 25351
lines
is a string array, so you can simply use:
lines[0]
But it is better to only read the first line unless you want the other lines in some other parts of your code.
Upvotes: 1
Reputation: 2003
var lines = File.ReadAllLines(path + "/resource.rpf" + "/" + "__resource.lua");
string firstLine = lines[0];
The best solution would be to only read in the first line to begin with:
using(StreamReader sr = new StreamReader(path" + "/resource.rpf" + "/" + "__resource.lua"))
{
string firstLine = sr.ReadLine();
}
Upvotes: 4