I want to know how, in C++, to search a string for the first instance of ANY of a list of strings. A kind of full-word version of std::string::find_first_of()
: "Searches the string for the first character that matches any of the characters specified in its arguments".
I want something that will search the string for the first WORD that matches any of the words in a provided list/array. To be clear, I don't want to search an array for an instance of a string. I want to search a string, for an instance of something in an array.
My goal is to be able to take a sentence, and remove all words that I have in a list. For example, if I give it the list {"the" "brown", "over"};
and the sentence, "the quick brown fox jumped over the lazy dog"
,
I want it to output, " quick fox jumped lazy dog"
.
And I want to be able to give it a list of even 100 words if I want; I need this to be expandable.
The only solution I can think of is to use std::find(stringArray[0])
in a while
loop on my block of text, and save the indexes that that word is found at, then put all that in another for
loop and do that on every single word in my array, saving the indexes of each word into one huge list. Optionally then numerically sorting that list, and finally then going through and removing each word that is at a position in that list.
I'm really hoping there's a function or an easier way to do it, because my solution seems difficult and VERY slow, especially since I need to use it many times, on many different strings, to go through all the sentences of a 50,000 character block of text. Anything better optimized would be preferred.