Looking for a line with the word Test in a text file: How to save the remaining lines in the second text file where there is no word Test .

I do this: Var OnovnoyF, fsave, fOstatok: TextFile;

// Поиск нужных строк if (pos('Test',S) > 0) then writeln(fsave, S); // Сохранения остатка // Поиск нужных строк if (pos('Test',S) < 0) then writeln(fOstatok, S); 

But the rest is not saved ... Where is the puncture?

  • one
    and why not write the else branch to the first condition? - teran 5:42 pm
  • @ teran, It turns out you had to do this: if (pos ('@', S)> 0) and (pos (f, S)> 0) then writeln (f1, S) else writeln (f2, S); - Denis

1 answer 1

pos('Test',S) < 0 - what does Pos return if a string fragment is not found?

  • Returns false? right ? - Denis
  • @ Denis Why are you ready to believe people from the Internet, instead of reading the documentation or conducting an experiment? The Pos function returns 0 . - Igor
  • @ Igor, It turns out it was necessary to do this: if (pos ('@', S)> 0) and (pos (f, S)> 0) then writeln (f1, S) else writeln (f2, S); - Denis
  • @ Denis Probably yes. This code is not in question. - Igor
  • And before that, I thought of as soon as you told me to read the documentation. By the way, it worked! Igor +++. I put you a well-deserved solution to the problem! - Denis