Reputation: 27
Can anybody please let me know how to check for a particular string in antoher string using VC++ 2003?
For Eg:
Soruce string - "I say that the site referenced here is not in configuration database. need to check"; String to find - "the site referenced here is not in configuration database"
can anybody please help me with this? Let me know if anymore clarity required.
Upvotes: 0
Views: 101
Reputation: 45410
std::string::find
might meet what you want, see this
string s1 = "I say that the site referenced here is not in configuration database. need to check";
string s2 = "the site referenced here is not in configuration database";
if (s1.find(s2) != std::string::npos){
std::cout << " found " << std::endl;
}
Upvotes: 3
Reputation: 116217
For C/C++, you can use strstr()
:
const char * strstr ( const char * str1, const char * str2 );
Locate substring
Returns a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not part of str1.
If you insist on pure C++, use std::string::find
:
size_t find (const std::string& str, size_t pos);
Find content in string
Searches the string for the content specified in either str, s or c, and returns the position of the first occurrence in the string.
Upvotes: 1
Reputation: 2138
string sourceString = "I say that the site referenced here is not in configuration database. need to check";
string stringToFind = "the site referenced here is not in configuration database";
sourceString.find(stringToFind); This method call will return you the postion of type size_t
Hope this helps you
Upvotes: 1