In the lines there are words ( day ). How to use the Delete procedure to delete everything after the second word of the day :

Самый лучший день сегодня день 2018. Не правда ли какой день хороший день сегодня день. день день Прекрасный. 

What would happen:

 Самый лучший день сегодня день Не правда ли какой день хороший день день день 
  • Pos function (Substr: String; Str: String): Integer Returns the position (index) of the first occurrence of Substr in the string Str. If Substr is not in Str, returns 0. the Insert function , Count: Integer) Removes from string S a substring beginning with the character number equal to Index and containing up to Count characters. - croll

1 answer 1

Just as in the previous question, combine search and delete:

 program Project1; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; const s0:array[0..2] of string = ('Самый лучший день сегодня день 2018.', 'Не правда ли какой день хороший день сегодня день.', 'день день Прекрасный.'); var k,i:integer; s:string; begin for i := 0 to High(s0) do begin s:=s0[i]; k:=Pos('день',s); if k > 0 then k:=Pos('день',s,k+1) else Continue; Delete(s,k+4,Length(s)-k-3); Writeln(s); end; Readln; end.