Delphi を使用して、特定の文字列の後に続くメモ フィールドからデータを削除するにはどうすればよいでしょうか。たとえば、データベース内のデータは次のように表示されます。
<Data I want to keep>
======= Old Data ========
<line 1>
<line 2>
etc.
古いデータ行の後 (およびそれを含む) のすべてのデータを削除するように Delphi に指示するにはどうすればよいですか? しかし、私が保持したいデータに触れませんか?
何かのようなもの:
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);
これを試して:
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;