Searches the string for the content specified in sequence
and returns the position of the first occurrence in the string.
This method returns the position of the first occurrence in the string of the searched content. If the content is not found, the constant NPOS
is returned.
string str = "There are two needles in this haystack with needles."; string str2 = "needle"; const uint found = str.find(str2); if (found != NPOS) print("first needle found at: " + found);
Output:
first needle found at: 14
The description above has been adapted from the std::string::find page on cplusplus.com.