Remove HTML after ckeditor is pasted
Last Update:2018-12-06
Source: Internet
Author: User
Public static string nohtml (string htmlstring)
{
// Delete the script
Htmlstring = htmlstring. Replace ("\ r \ n ","");
Htmlstring = RegEx. Replace (htmlstring, @ "<script .*? </SCRIPT> "," ", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "<style .*? </Style> "," ", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "<. *?> "," ", Regexoptions. ignorecase );
// Delete HTML // & ndash;
Htmlstring = RegEx. Replace (htmlstring, @ "<(. [^>] *)>", "", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "([\ r \ n]) [\ s] +", "", regexoptions. ignorecase );
Htmlstring = RegEx. Replace (htmlstring, @ "& ndash;", "-", regexoptions. ignorecase); // 1
Htmlstring = RegEx. Replace (htmlstring, @ "& ldquo;", "", regexoptions. ignorecase); // 2
Htmlstring = RegEx. Replace (htmlstring, @ "& rdquo;", "", regexoptions. ignorecase); // 3 replicas are added
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 = htmlstring. Replace ("<","");
Htmlstring = htmlstring. Replace ("> ","");
Htmlstring = htmlstring. Replace ("\ r \ n ","");
Htmlstring = httpcontext. Current. server. htmlencode (htmlstring). Trim ();
Return htmlstring;
}