If I understood you correctly you want to retrieve from 1 till end, from 2 till end or from 3 till end.
I don't know why but I would expect that you want from 1 to 2, from 2 to 3 or from 3 to end.
Nevertheless the simplest way how you can do this is to just read each line until you find your starting line and when you do then just read the rest of the text file and return that content.
So something like this:
private static string ReadPartialText(string filePath, string startingLine)
{
using (var reader = new StreamReader(filePath))
{
bool startingLineFound = false;
while (!startingLineFound && !reader.EndOfStream)
startingLineFound = reader.ReadLine().Equals(startingLine);
return (startingLineFound) ? reader.ReadToEnd() : string.Empty;
}
}
And you can use it like this:
string partialText = ReadPartialText("C:\\Sample.txt", "2");
Also just in case I misunderstood you and you actually want to read between 1 and 2 or 2 and 3, etc. in that case instead of using
ReadToEnd
you will want to continue reading line by line, after you found the starting line you will add those lines into a
StringBuilder
and when you find an ending line then you will return the
StringBuilder
's content.