user863551
user863551

Reputation:

Removing Specific Lines From Contents of a Memo field

How would I be able to use Delphi to remove data from a memo field that comes after a certain string, for example the data in the database I'm going through it displayed as such:

<Data I want to keep>

======= Old Data ========
<line 1>
<line 2>
etc.

How could I tell Delphi to remove all data after (and including) the old data line? But not touch the data that I wish to keep?

Upvotes: 2

Views: 1796

Answers (2)

Mason Wheeler
Mason Wheeler

Reputation: 84550

Try this:

procedure myForm.ClearFromLine(value: string);
var
  i, index: integer;
begin
  index := memo.lines.IndexOf(value);
  if index = -1 then
    Exit;
  memo.lines.BeginUpdate;
  try
    for i := memo.lines.count - 1 downto index do
      memo.lines.delete(i);
  finally
    memo.lines.EndUpdate;
  end;
end;

Upvotes: 1

Francesca
Francesca

Reputation: 21640

something like:

var
  I: Integer;
  s: string;
begin
  s := 'your big string with ======= Old Data ======== and more';
  I:=Pos('======= Old Data ========',s);
  if I>0 then
    Delete(s, I, MaxInt);
  ShowMessage(s);

Upvotes: 7

Related Questions