DELPHI 去掉字符串中的HTML标记,返回纯文本

   function StripHTML(S: string): string;
  var
    TagBegin, TagEnd, TagLength: integer;
  begin
    TagBegin := Pos( '<', S);      // 查找第一个<
 
    while (TagBegin > 0) do begin  // 若S串中含有<
      TagEnd := Pos('>', S);              // 查找匹配的 >
      TagLength := TagEnd - TagBegin + 1;
      Delete(S, TagBegin, TagLength);     // 删除两次匹配之间的字符
      TagBegin:= Pos( '<', S);            // 查找下一个<
    end;
 
    Result := S;                   // 返回结果
  end;

你可能感兴趣的:(delphi,html,integer,string,delete,function)