Delete all instance of variable substring between tags in Delphi

后端 未结 1 1627
温柔的废话
温柔的废话 2021-01-21 20:26

I\'m extracting readable text from HTML into a string and I need to remove the existing text between the tags. What would be the

相关标签:
1条回答
  • 2021-01-21 20:44

    Try something like this:

    function RemoveIEScripts(const s: string): string; 
    var 
      I, J: Integer; 
    begin 
      Result := s; 
      I := 1;
      repeat
        I := PosEx('<!--', Result, I);
        if I = 0 then Break;
        J := PosEx('-->', Result, I+4); // 4 = Length('<!--')
        if J = 0 then Break;
        Delete(Result, I, (J+3)-I); // 3 = Length('-->')
      until False;
    end; 
    
    0 讨论(0)
提交回复
热议问题