Reputation: 197
Basically I want to check a string array to see if any of the words match "and".
Thanks
I should make it clear that the words are char put together best way to explain is an example
abc defg hijk and lmnop <-- each character is in its own element
Upvotes: 0
Views: 2131
Reputation: 1223
I am guessing you'd like to take care of lower\upper casing and the word appearing in the beginning\end of the string.
std::string data;
std::transform(data.begin(), data.end(), data.begin(), ::tolower);
data.append(' ');
if (data.find("and ") != std::string::npos) ......
Upvotes: 0
Reputation: 62063
I recommend you use std::string
and not null-terminated char*
strings (maybe you already are -- hard to be sure). And use a standard container rather than an array. Then use std::find
(which would work on an array too, but containers are better).
Upvotes: 2
Reputation: 258568
Iterate through the array and use int string::compare ( const string& str ) const;
to check for matches.
Break from the loop on first match.
Upvotes: 1