P
P
Paul2016-08-26 09:17:11
Programming
Paul, 2016-08-26 09:17:11

How to read data from a file in C#, starting from a certain position?

I read the file line by line. The task is to start reading from some (undefined string), starting from this string and ending with a string containing the character "}"

string[] currentLine;
string line;
System.IO.StreamReader file = new System.IO.StreamReader(some_file);
while ((line = file.ReadLine()) != null)
{
     currentLine = line.Split(' '); // Разбиваю каждую строку на слова
     for (int element = 0; element < currentLine.Length; element++)
     {
          if (currentLine[element] == "word") // Если встретилось определенное слово
          {
                 // начать считывать следующие строки файла, до того, как встретится "}"
                 // Зачем это нужно? Необходимо запомнить само слово "word" и проанализировать 
                 // следующий отрывок текста до "}", В тексте много "}"
                 // необходимо проанализировать текст после слова word и до первого "}" 
          }
     }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2016-08-26
@PashaKrizskiy

Maybe this will help you

A
akass, 2016-08-26
@akass

What prevents you from doing File.ReadAllText, then using String.IndexOf to find the word, and then find it in the same way }, but already from the word index? Well, then take the desired substring.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question