Reputation:
I have this bit of code where I start reading a CSV file after a certain line. I was wondering if there is a way to also stop reading a CSV file after a certain line. OR, is there a way to stop reading the CSV file after I read a specific string. Stopping before a certain row would be better but. Let me know what you think. If there even is a way.
public List<ResultantRead> processCSVFile()
{
alist = File.ReadAllLines("C:/Users")
.Skip(54);
.Select(v => ResultantRead.readCsv(v))
.ToList();
return alist;
}
Upvotes: 0
Views: 245
Reputation: 22443
public IEnumerable<ResultantRead> processCSVFile()
{
return File.ReadLines("C:/Users")
.Skip(54);
.Select(v => ResultantRead.readCsv(v));
}
//calling code
var result = processCSVFile().Take(5).ToList();
// result will only enumerate 59 rows (or less) from the file
Upvotes: 2
Reputation: 114
alist = File.ReadLines("C:/Users").take(250);
I think that will tell it to stop after 250 lines, but I am not sure how that will jive with skip, as in, will it skip 54 lines then take the next 250 or take 250 lines and skip 54 of them.
I would give it a try
Upvotes: 0