procedure TForm1.Button4Click(Sender: TObject); var k: integer; begin for k:=1 to memo1.Lines.Count-1 do begin if AnsiPos('%', Memo1.Lines.Strings[k]) <>0 then begin // Edit1.Text := ? end; end; end; 

There is a loop in Button that watches every line in Memo. If the first character '%' is found, but how to make the Edit add all the characters after it until the same character is found?

Sample text in Memo:

% Here is some text needed to move it somewhere.%

What should appear in Edit:

Here is some text needed to move it somewhere.

    1 answer 1

    Let's make a function that takes a string of text and returns everything between %%:

     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; 

    PS Naturally, you will need to envisage the behavior for cases when the text contains not two % signs, but more or less.

    • Writes: Undeclared identifier: 'PosEx' - Nick
    • one
      In the uses section, you need to add the module StrUtils - androschuk
    • Does not unload several lines. Apparently because it exceeds the number of available characters. How to be? - Nick
    • @ Nick This is because of line breaks. Add a clarification to the question or ask a new one) - Kromster