. Net filters specific code

Source: Internet
Author: User

# Region // filter html, js, and css code
/// <Summary>
/// Filter html, js, and css code
/// </Summary>
/// <Param name = "html"> parameter input </param>
/// <Returns> </returns>
Public static string CheckStr (string html)
{
System. text. regularExpressions. regex regex1 = new System. text. regularExpressions. regex (@ "<script [\ s \ S] + </script *>", System. text. regularExpressions. regexOptions. ignoreCase );
System. text. regularExpressions. regex regex2 = new System. text. regularExpressions. regex (@ "href * = * [\ s \ S] * script *:", System. text. regularExpressions. regexOptions. ignoreCase );
System. text. regularExpressions. regex regex3 = new System. text. regularExpressions. regex (@ "no [\ s \ S] * =", System. text. regularExpressions. regexOptions. ignoreCase );
System. text. regularExpressions. regex regex4 = new System. text. regularExpressions. regex (@ "<iframe [\ s \ S] + </iframe *>", System. text. regularExpressions. regexOptions. ignoreCase );
System. text. regularExpressions. regex regex5 = new System. text. regularExpressions. regex (@ "<frameset [\ s \ S] + </frameset *>", System. text. regularExpressions. regexOptions. ignoreCase );
System. text. regularExpressions. regex regex6 = new System. text. regularExpressions. regex (@ "\ ] + \>", System. text. regularExpressions. regexOptions. ignoreCase );
System. Text. RegularExpressions. Regex regex7 = new System. Text. RegularExpressions. Regex (@ "</p>", System. Text. RegularExpressions. RegexOptions. IgnoreCase );
System. Text. RegularExpressions. Regex regex8 = new System. Text. RegularExpressions. Regex (@ "<p>", System. Text. RegularExpressions. RegexOptions. IgnoreCase );
System. Text. RegularExpressions. Regex regex9 = new System. Text. RegularExpressions. Regex (@ "<[^>] *>", System. Text. RegularExpressions. RegexOptions. IgnoreCase );
Html = regex1.Replace (html, ""); // filter <script> </script> tags
Html = regex2.Replace (html, ""); // filter javascript: (<A>) attributes
Html = regex3.Replace (html, "_ disibledevent ="); // filter events of other controls.
Html = regex4.Replace (html, ""); // filter iframe
Html = regex5.Replace (html, ""); // filter frameset
Html = regex6.Replace (html, ""); // filter frameset
Html = regex7.Replace (html, ""); // filter frameset
Html = regex8.Replace (html, ""); // filter frameset
Html = regex9.Replace (html ,"");
Html = html. Replace ("","");
Html = html. Replace ("</strong> ","");
Html = html. Replace ("<strong> ","");
Return html;
}
# Endregion
# Region // filter p/p code
/// <Summary>
/// Filter p/p code
/// </Summary>
/// <Param name = "html"> parameter input </param>
/// <Returns> </returns>
Public static string InputStr (string html)
{
Html = html. Replace (@ "\ ] + \> ","");
Html = html. Replace (@ "<p> ","");
Html = html. Replace (@ "</p> ","");
Return html;
}
# Endregion


/// <Summary>
/// Capture a string
/// </Summary>
/// <Param name = "str"> </param>
/// <Param name = "length"> </param>
/// <Returns> </returns>
Protected string GetLength (string str, int length)
{
String strR = str;
If (str. Length> length)
{
StrR = str. Substring (0, length) + "...";
}
Return strR;
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.