I recently had a requirement on a client project that we should attempt to filter out any bad words or phrases from the public facing pages. It had to be case insensitive and, as you've just read, able to filter out phrases instead of just individual words.
Here's a simple C# extension method to help you filter out bad words, then call the method on whatever text you'd like to clean up, like so:
Here's the code. It should simply become a new Extension method in the same vein as ".ToString()" is on any string object.
It works quite well, but I plan to add to it in the future to allow a whitelist of phrases which may or may not contain any of the objectional words or phrases. It would probably also be beneficial to have the list of words and phrases populated from a database or configuration file so that you can add new words without requiring a whole new application build to be compiled.
I hope this helps :)
You can fork this code on GitHub here: https://github.com/woodss/PottyMouth/;
Please consider what you post!
Chillax if you're angry.