Use C # to do simple information filtering

Source: Internet
Author: User

Now online relatively large forums have to record, once there is any unreasonable information, may be affected by the Department of that what ... So in the information filtering seems to have a bit of status. below to introduce a simple information hard filtering method. is actually automatic matching. The code is as follows: public void Checkwords (String str)
{
Create an array to write the string to filter
String[] Badwords=new string[2];

Badwords[0]= "C";
badwords[1]= ". NET";

System.Text.RegularExpressions.Regex re;

for (int i=0;i<2;i++)//a loop check to see if a predetermined string is included
{
Re=new System.Text.RegularExpressions.Regex (Badwords[i]);
if (re. Match (str). Success)
{
Response.Write ("Capture to a predetermined information:");
Response.Write (Badwords[i]);
Response.Write ("<br>");
}
}
}

When used, the code is

String str= "C#.net";
Checkwords (str);

We can according to this example, free play, should be able to make better information filter things to.

In the analysis of information filtering, we can also consider using it to retrieve information, or other uses. I hope you can gain something. I have a limited level, and you are welcome to criticize.



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.