function GetTextInPercent(aLine: string): string; var i1, i2: Integer; begin i1 := Pos('%', aLine) + 1; i2 := PosEx('%', aLine, i1); Result := Copy(aLine, i1, i2 - i1); end; procedure TForm1.Button4Click(Sender: TObject); var k: integer; begin for k:=0 to memo1.Lines.Count-1 do begin Que1.Lines.Text := Que1.Lines.Text + GetTextInPercent(Memo1.Lines.Strings[k]); end; end; 

There is a procedure that allows you to search in the Memo text the symbol '%' and output after it everything that is after it until the same '%' is found. But this only works if characters are on a single line.
How to make to display several lines?
Sample text in Memo (Memo1):

In the spring, the snow quickly melted, the water rose and flooded the beaver's hut. The beavers dragged the beaver onto dry leaves, but the water crept even higher, and the beavers had to spread to different directions. (Snegiryov G.)%

Example result in another Memo (Que1):

In the spring, the snow quickly melted, the water rose and flooded the beaver's hut. The beavers dragged the beaver onto dry leaves, but the water crept up even higher, and the beavers had to spread in different directions. (Snegirev G.)

    1 answer 1

    In this scenario, you need to somehow handle the entire text:

    In general, the principle is that we take the whole text, we find the first% using PosEx('%', aText, 1) , we also find the second%, we take the text between them using Copy . And then we repeat it in a cycle, we find 3 and 4%, then 5 and 6, and each time we take the text between them.

    Or, somehow, divide the input text into parts so that each has only two% signs and passes it to your function not in a line, but all at once (for example, Memo1.Text ) (then line Memo1.Text be saved)