1 usingSystem.Text.RegularExpressions;2 3 /// <summary>4 5 ///Remove HTML Tags6 7 /// </summary>8 9 /// <param name= "deletehtml" >including the HTML source code</param>Ten One /// <returns>text after HTML tag has been removed</returns> A - Public Static stringDeletehtml (stringhtmlstring) - the { - - //Delete Script - +htmlstring = Regex.Replace (htmlstring,@"<script[^>]*?>.*?</script>","", regexoptions.ignorecase); - + //Delete HTML A athtmlstring = Regex.Replace (htmlstring,@"< (. [ ^>]*) >","", regexoptions.ignorecase); - -htmlstring = Regex.Replace (htmlstring,@"([\ r \ n]) [\s]+","", regexoptions.ignorecase); - -htmlstring = Regex.Replace (htmlstring,@" -","", regexoptions.ignorecase); - inhtmlstring = Regex.Replace (htmlstring,@"<!--. *","", regexoptions.ignorecase); - to + -htmlstring = Regex.Replace (htmlstring,@"& (quot| #34);","\"", regexoptions.ignorecase); the *htmlstring = Regex.Replace (htmlstring,@"& (amp| #38);","&", regexoptions.ignorecase); $ Panax Notoginsenghtmlstring = Regex.Replace (htmlstring,@"& (lt| #60);","<", regexoptions.ignorecase); - thehtmlstring = Regex.Replace (htmlstring,@"& (gt| #62);",">", regexoptions.ignorecase); + Ahtmlstring = Regex.Replace (htmlstring,@"& (nbsp| #160);"," ", regexoptions.ignorecase); the +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); - thehtmlstring = Regex.Replace (htmlstring,@"& (copy| #169);","\xa9", regexoptions.ignorecase); - Wuyihtmlstring = Regex.Replace (htmlstring,@"(\d+);","", regexoptions.ignorecase); the -Htmlstring.replace ("<",""); Wu -Htmlstring.replace (">",""); About $Htmlstring.replace ("\ r \ n",""); - -htmlstring=HttpContext.Current.Server.HtmlEncode (htmlstring). Trim (); - A returnhtmlstring; + the}
. NET removing HTML markup