I need to check if a string contains any abusive words.
Following the advice of another question here, I created a HashSet containing the words:
HashSet<string> swearWords = new HashSet<string>() { "word_one", "word_two", "etc" };
Now I need to see if any values from are swearWordsin my line.
I saw how this was done the other way around, for example:
swearWords.Contains(myString)
But this will return false.
What is the fastest way to check if any of the words in a HashSet are in myString?
NB: I suppose I can use the foreach loop to check each word in turn and break if a match is found, I'm just wondering if there is a faster way.
source
share