C# – Masking words in a text

Imagine you are the owner of a web site with a lot of comments (not like this one, where noone comments due to the fact that he should do it with his Facebook account 🙂 ). In this site there are people, who probably would love to share with you their opinion about the last derby match between <put any football derby here>. The point is that there are probably some words that you would like to avoid. What you can do, is to create a program, masking these words for you. Something like the following:

What have I done? I have hardcoded the input, in order to save place. Then for each word in the list of the “forbidden” words (in my case they are quite trivial and normal), I run a foreach loop, generating a string sPattern, with the size of the forbidden word and changing it, if it is present.


Enjoy the code 🙂 :


Tagged with: ,