When people type text into a textfield, before it is added to the textbox (for chat) there are certain words I want to look for and filter. This includes if they are not space spliced example the word space in spaceship.
What sort of algorithm is generally used for this sort of purpose?
The only algorithm I can think of iterates over the text for each word:
for each word to filter
for each char in string
if the substring from index of the first letter of word to the current index == word, do something with the word
end for each
end for each
Is there a better, more O(n) way to do it?
Thanks
Tries can be used for pretty much exactly this problem.