Public static string nohtml (string htmlstring)
{
// Delete the 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, @ "& (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 ();
Return htmlstring;
}
Using system. Text. regularexpressions; // you need to reference
// Use the regular expression to remove the content between "<" and ">"
Private string stripht (string strhtml)
{
RegEx = new RegEx ("<. +?> ", Regexoptions. ignorecase );
String stroutput = RegEx. Replace (strhtml ,"");
Return stroutput;
}