Write down for backup first!
/// <Summary> Remove HTML tags
///
/// </Summary>
/// <Param name = "htmlstring"> Including the source code of HTML </Param>
/// <Returns> Removed text </Returns>
Public Static String Getnohtmlstring ( String Htmlstring)
{
// Delete script
Htmlstring = RegEx. Replace (htmlstring, @" <SCRIPT [^>] *?>. *? </SCRIPT> " , "" , Regexoptions. ignorecase );
// Delete HTML
Htmlstring = RegEx. Replace (htmlstring, @" <(. [^>] *)> " , "" , Regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @" ([\ R \ n]) [\ s] + " , "" , Regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @" --> " , "" , Regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @" <! --.* " , "" , Regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @" & (Quot | #34 ); " , " \ "" , Regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @" & (Amp | #38 ); " , " & " , Regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @" & (LT | #60 ); " , " < " , Regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @" & (GT | #62 ); " , " > " , Regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @" & Amp; (nbsp | #160 ); " , " " , Regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @" & (Iexcl | #161 ); " , " \ XA1 " , Regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @" & (Cent | #162 ); " , " \ Xa2 " , Regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @" & (Pound | #163 ); " , " \ Xa3 " , Regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @" & (Copy | #169 ); " , " \ Xa9 " , Regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @" (\ D + ); " , "" , Regexoptions. ignorecase );
Htmlstring. Replace (" < " , "" );
Htmlstring. Replace ( " > " , "" );
Htmlstring. Replace ( " \ R \ n " , "" );
Htmlstring = Httpcontext. Current. server. htmlencode (htmlstring). Trim ();
ReturnHtmlstring;
}
/// <Summary> Obtain the displayed string to display HTML tags, but filter dangerous HTML tags, such as IFRAME and script.
///
/// </Summary>
/// <Param name = "str"> Unprocessed string </Param>
/// <Returns> </returns>
Public Static String Getsafehtmlstring ( String Str)
{
Str = RegEx. Replace (STR, @" <APPLET [^>] *?>. *? </APPLET> " , "" , Regexoptions. ignorecase );
Str = RegEx. Replace (STR, @" <Body [^>] *?>. *? </Body> " , "" , Regexoptions. ignorecase );
Str = RegEx. Replace (STR, @" <Embed [^>] *?>. *? </Embed> " , "" , Regexoptions. ignorecase );
Str = RegEx. Replace (STR, @" <Frame [^>] *?>. *? </Frame> " , "" , Regexoptions. ignorecase );
Str = RegEx. Replace (STR, @" <SCRIPT [^>] *?>. *? </SCRIPT> " , "" , Regexoptions. ignorecase );
Str = RegEx. Replace (STR, @" <Frameset [^>] *?>. *? </Frameset> " , "" , Regexoptions. ignorecase );
Str = RegEx. Replace (STR, @" <HTML [^>] *?>. *? </Html> " , "" , Regexoptions. ignorecase );
Str = RegEx. Replace (STR, @" <IFRAME [^>] *?>. *? </Iframe> " , "" , Regexoptions. ignorecase );
Str = RegEx. Replace (STR, @" <Style [^>] *?>. *? </Style> " , "" , Regexoptions. ignorecase );
Str = RegEx. Replace (STR, @" <Layer [^>] *?>. *? </Layer> " , "" , Regexoptions. ignorecase );
Str = RegEx. Replace (STR, @" <Link [^>] *?>. *? </Link> " , "" , Regexoptions. ignorecase );
Str = RegEx. Replace (STR, @" <Ilayer [^>] *?>. *? </Ilayer> " , "" , Regexoptions. ignorecase );
Str = RegEx. Replace (STR, @" <Meta [^>] *?>. *? </Meta> " , "" , Regexoptions. ignorecase );
Str = RegEx. Replace (STR, @" <Object [^>] *?>. *? </Object> " , "" , Regexoptions. ignorecase );
Return STR;
}