Searches this string for the match of a character.
This overloaded member function searches this string for the match of a substring.
int Find( char ch, int nStart = 0 )
int Find( LPCSTR lpcszSub, int nStart = 0, BOOL bCaseSensitive = TRUE )
Returns the zero-based index of the first character in this string object that matches the character or the requested substring. It will return -1 if not found.
EX1
// Find a single character void string_Find_ex1() { //Search character from the beginning, character is case-sensitive string str("abcdef"); int nRet = str.Find('c'); out_int("", nRet); // 2 nRet= str.Find('C'); out_int("", nRet); // Can not be found, nRet = -1 //Search character from the specified index, character is case-sensitive nRet = str.Find('c',1); // Search from the second char out_int("", nRet); // 2 nRet = str.Find('c',4); // Search from the fifth char out_int("", nRet); // -1 }
EX2
// Find a string void string_Find_ex2() { //Search a string from the beginning, character is case-sensitive string str("abcdef"); int nRet = str.Find("de"); out_int("", nRet); // 3 nRet= str.Find("De"); out_int("", nRet); // Can not be found, nRet = -1 //Search a string from the specified index, character is case-sensitive nRet = str.Find("de",1); //search from the second char out_int("", nRet); // 3 nRet = str.Find("de",4); //search from the fifth char out_int("", nRet); // -1 //Search a string from the specified index, character is case-insensitive nRet = str.Find("DE",1,FALSE); out_int("", nRet); // 3 }
string::FindOneOf, string::ReverseFind
origin.h