1

I have a multi-line string and I want to remove some lines from it. The TMemo component contains the necessary code to do this.

MyMemo:=TMemo.Create(nil);
try
   MyMemo.Text:=MyString;
   MyMemo.Lines.Delete(x); // lines I want to delete
   MyMemo.Lines.Delete(y);
   MyString:=MyMemo.Text;
finally
   MyMemo.Free;
end;

But it seems wrong to use a visual component to do basic conversions. Is there a different, but equally simple, way to do this? Thanks

kaj66
  • 153
  • 1
  • 11

2 Answers2

5

You have the answer right in the question title - use a TStringList:

procedure MyProcedure(var MyString: string);
var
  sl: TStringList;
begin
  sl := TStringList.Create;
  try
    sl.Text := MyString;
    sl.Delete(x); // lines I want to delete
    sl.Delete(y);
    MyString := sl.Text;
  finally
    sl.Free;
  end;
end;
Uli Gerhardt
  • 13,748
  • 1
  • 45
  • 83
0

I've just realised that TStringlist itself has a Text property. So that answers my own question.

kaj66
  • 153
  • 1
  • 11