尽管您的方法有效,但可能会耗费一些时间。对于之前的SO问题,有一个wonderful response here。虽然这个问题谈论的是PHP而不是C#,但我认为它可以很容易地移植。
编辑补充示例代码:
public string FilterWords(string inputWords) {
Regex wordFilter = new Regex("(puppies|kittens|dolphins|crabs)");
return wordFilter.Replace(inputWords, "<3");
}
这应该为你工作,或多或少。
编辑回答OP澄清:
我不希望删除淫秽自动...我的web应用程序,我想我们会通知您一个字,我认为“坏”字。
就像上面的替换部分,你可以看到,如果像这样匹配:
public bool HasBadWords(string inputWords) {
Regex wordFilter = new Regex("(puppies|kittens|dolphins|crabs)");
return wordFilter.IsMatch(inputWords);
}
它将返回true
,如果你传递给它的字符串包含列表中的任何话。
我继续编辑我的解决方案以响应您的更新。让我知道这是否回答你的问题。 – rakuo15 2010-07-09 10:29:02
可能的重复[你如何实现一个良好的亵渎过滤?](http://stackoverflow.com/questions/273516/how-do-you-implement-a-good-profanity-filter) – 2010-10-22 16:21:53