Reputation: 1455
I have a text file which i do need to read line by line.Now as per my requirement i have to read text file after 65 lines.for this i am trying to use skip() but its not working ..Here is my code ..
string FileToCopy = "D:\\tickets.txt";
if (System.IO.File.Exists(FileToCopy) == true)
{
var fs = new FileStream(FileToCopy, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using (var reader = new StreamReader(fs))
{
string line;
string rawcdr="";
while (true)
{
while ((line = reader.ReadLine()).Skip(65) != null)
{
if (line != "")
{
rawcdr = line.ToString();
}
var strings = rawcdr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (strings.Length != 0)
{
}
}
}
}
}
On executig above code.Text file is being read from first line whereas i do need to read from 66 line..Where am i going wrong?
Upvotes: 0
Views: 405
Reputation: 100547
File.ReadAllLines with Enumerable.Skip may work for you
var listOfOtherLines = File.ReadAllLines(filename).Skip(65).ToList();
Upvotes: 1
Reputation: 101701
Why don't you use File.ReadAllLines
?
var lines = File.ReadAllLines("D:\\tickets.txt")
.Skip(65);
foreach(var line in lines)
{
// do what you want with other lines...
}
Upvotes: 1