Domanda

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?

È stato utile?

Soluzione

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);

Altri suggerimenti

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;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top