Answer the question
In order to leave comments, you need to log in
How to read a file sequentially from the desired line number?
How to read a file sequentially from the desired line number. I find the first line to read like this
while ((line = text.ReadLine()) != null)
{
if (line.Contains("Накладная: " + docNum))
{
System.Console.WriteLine(line);
System.Console.WriteLine("There were {0} lines 1.", counter);
counter1n = counter;
System.Console.WriteLine(line);
}
counter++;
}
line.Contains("Дата отгрузки")
Answer the question
In order to leave comments, you need to log in
Personally, I don't like the idea of being hardwired to line numbers and expecting a line with certain content to be followed by lines with the right data.
I don't think you're approaching the question correctly.
What is this file format? Maybe it needs to be parsed differently?
If you yourself came up with the idea of exchanging data in this way, then you should look towards more structured formats, such as JSON, YAML and XML.
If you still need to read line by line, then there are: File.ReadAllLines and StreamReader.ReadLine
On average, it should look something like this:
var lines = EnumerateLines(stream); // Некоторый наш метод, который превращает стрим в поток строк
var expectedLine = $"Накладная: {docNum}";
var dataLines = lines.SkipWhile(line => !line.Contains(expectedLine));
var data = ParseLines(dataLines); // Некоторый наш метод, который парсит данные
counter1n
and give the whole code, otherwise it is not clear from your example where this variable is declared in general and how it is used.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question