I have a bad word list. If a string contains any of item/items from the bad word list, I need to remove that bad word from the string.
List<string> badWordList = new List<string> { "email:", "index", "mobile:", "fax:", "web" };
I am able to search the string but not able to remove. Please help me out...I tried below code:
string myText = "email:[email protected]";
if (badWordList.Any(w => myText.IndexOf(w, StringComparison.OrdinalIgnoreCase) >= 0))
{
// How to remove
}
Below is the set of input of expected output:
i/p- email:[email protected]
o/p - [email protected]
i/p- Jack F. Mobile:89788987
o/p- Jack F. 89788987
i/p- Jack F. Email:[email protected] mobile:65777 WEB
o/p- Jack F. [email protected] 65777
I would prefer a non-regex approach. Thanks for your help.

myText = myText.Replace(badWordList.First(i => myText.IndexOf(w, StringComparison.OrdinalIgnoreCase) >= 0), "");Generally, if this is going to handle user-input, be sure that it won't.