Re: How to strip HTML tags and just get the text
- From: JimL <me@xxxxxxxxxxx>
- Date: Wed, 29 Jun 2005 09:06:08 -0500
You posted a function that Delphi didn't put in my copy????
POSR
On Tue, 28 Jun 2005 17:37:37 +0300, "Aleksey Kuznetsov"
<nospam@xxxxxxxxxx> wrote:
>I decided to post this function. Any additions and comments welcome...
>
>{ removes the tags (all text withing <> brackets) from the string and
>returns the text without tags }
>function StripTags(const St: String): String;
>var
> B, E, SB, T: Integer;
>begin
> // todo: smarter parsing... actually " > " and " < " occurances can be
>allowed as usual text...
> Result := StringReplace(St, '"', '"', [rfReplaceAll, rfIgnoreCase]);
> Result := StringReplace(Result, '&', '&', [rfReplaceAll,
>rfIgnoreCase]);
> Result := StringReplace(Result, '©', '(c)', [rfReplaceAll,
>rfIgnoreCase]);
> Result := StringReplace(Result, ' ', ' ', [rfReplaceAll,
>rfIgnoreCase]);
> Result := StringReplace(Result, '—', '--', [rfReplaceAll]);
> Result := StringReplace(Result, ' ', ' ', [rfReplaceAll]);
> repeat
> B := Pos('<', Result);
> E := Pos('>', Result);
> if E = 0 then // if there is no ">" anymore
> begin
> if B <> 0 then
> Delete(Result, B, MaxInt); // this was last occurance of "<"
> // else -- no more tags
>
>{ StringReplace(Result, #13#10#13#10, #13#10, [rfReplaceAll]);
> StringReplace(Result, #10#10, #10, [rfReplaceAll]);}
> Result := Trim(Result);
> Break;
> end;
>
> if (B = 0) or (E < B) then // occurance of ">" without "<"... remove
>everything before ">"
> Delete(Result, 1, E)
> else
> begin
> T := E - B + 1;
> SB := PosR('<', Copy(Result, B + 1, T - 1));
> if SB <> 0 then // there is another "<" before ">"
> Delete(Result, SB + B, T - SB)
> else // normal tag
> Delete(Result, B, T);
> end;
> until False;
>
> Result := StringReplace(Result, '<', '<', [rfReplaceAll,
>rfIgnoreCase]);
> Result := StringReplace(Result, '>', '>', [rfReplaceAll,
>rfIgnoreCase]);
>end;
>
.
- References:
- How to strip HTML tags and just get the text
- From: Andrew Diabo
- Re: How to strip HTML tags and just get the text
- From: Aleksey Kuznetsov
- Re: How to strip HTML tags and just get the text
- From: Aleksey Kuznetsov
- How to strip HTML tags and just get the text
- Prev by Date: Re: IntraWeb like package ?
- Next by Date: Re: Looking for wysiwyg HTML authoring component
- Previous by thread: Re: How to strip HTML tags and just get the text
- Next by thread: Re: How to strip HTML tags and just get the text
- Index(es):
Relevant Pages
|