Usuń wszystkie instancje zmiennych podłańcuchów między znacznikami w Delphi

Wyodrębniam czytelny tekst z HTML do łańcucha i muszę usunąć istniejący tekst między<!-- i--> tagi. Jaki byłby najskuteczniejszy sposób osiągnięcia tego celu?

W tej chwili robię to w ten sposób:

function RemoveIEScripts(const s: string): string;
var
  i: Integer;
  InTag: Boolean;
begin
   Result := '';
   InTag := False;
   for i := 1 to Length(s)-3 do
   begin
      if (s[i] = '<') and (s[i+1] = '!') and (s[i+2] = '-') then
         inTag := True
      else if (s[i] = '-') and (s[i+1] = '-') and (s[i+2] = '>') then
             inTag := False
           else if not InTag then
      Result := Result + s[i];
   end;
end;

Czy jest lepszy sposób, aby to zrobić?

questionAnswers(1)

yourAnswerToTheQuestion