Given the text:
123456789:aaaa-!-www 123456789:aaaa-Z-www 1234-!-56789:aaaawww 12345-Z-6789:aaaawww Task: In edit - we write the characters "!" and "Z" and the program excludes all lines, where after the ":" sign there are "!" and "Z".
The output should be:
1234-!-56789:aaaawww 12345-Z-6789:aaaawww I did it like this: It works, but for some reason, the whole line is taken into account . But what is needed is a search to occur after the - symbol ":" . How to fix it ?
procedure TForm1.Button1Click(Sender: TObject); const D = [' ', #9, #10, #13]; var fall, f1: TextFile; Da : set of Char; i, Len, LenW, CntA : Integer; S,L, R: String; g:Tstringlist; begin //Открываем диалог выбора файла if OpenDialog1.Execute then begin g:=Tstringlist.Create; //Составляем множетсво букв. В множество добавляем строчный и заглавный //варианты букв. S := Edit1.Text; // В Edit записываем список символов Da := []; for i := 1 to Length(S) do if not (S[i] in D) then Da := Da + [ AnsiUpperCase(S[i])[1], AnsiLowerCase(S[i])[1] ]; if Da = [] then begin ShowMessage('Буквы не заданы. Действие отменено.'); Exit; end; AssignFile(fall, OpenDialog1.FileName); reset(fall); end; //работаем по строкам в файле while not Eof(fall) do begin //читаем строку ReadLn(fall, S); Len := Length(S); LenW := 0; CntA := 0; for i := 1 to Len do begin //Пропускаем разделители. if S[i] in D then Continue; //Подсчёт заданных букв в слове. if S[i] in Da then Inc(CntA); //Уточняем длину слова. Inc(LenW); //Отслеживаем конец слова. if (i = Len) or (S[i + 1] in D) then begin //Если заданных букв нет в слове - распечатываем его. if CntA = 0 then // Записываем рзультат g.Add( Copy(S, i - LenW + 1, LenW) ); //Сброс счётчика заданных букв. CntA := 0; //Сброс длины слова. LenW := 0; end; end; end; g.SaveToFile('Результат.txt'); g.Free; CloseFile(fall); end;