One: Before the implementation of the first find_first_not_of sister function ()
(1) find_first_of (string &str, Size_type index = 0): (Find_first_of implementation of the following link: find_first_of source code)
Finds the first character in a string that matches a character in Str and returns its position. search starts from index forward and returns String::npos if not found
(2) find_first_not_of (CString &str, Size_type index = 0):
Finds the first character in a string that does not match the character in Str and returns its position. The search starts from index forward . If you don't find it, return to String::nops.
(3) find_last_of (CString &str, Size_type index = 0):
Finds the last character in a string that matches a character in Str and returns its position. search starts at the reverse of index . If you don't find it, return to String::nops.
(4) find_last_not_of (CString &str, Size_type index = 0):
Finds the last character in a string that does not match the character in Str and returns its position. search starts at the reverse of index . If you don't find it, return to String::nops.
(5) Total (3) and (4) lookup from the reverse of index, also equivalent to (1) and (2) in the first
Two: manually implement the find_first_of() function
Finds the first character in a string that does not match the character in Str and returns its position. The search starts at index. Returns String::nops O (n^2) int mystring::find_first_not_of if not found (const char *str,size_t index) {if (NULL = = STR | | Index >=strlength) return NPOs; size_t i=0,j=0; size_t Tmp_len = strlen (str); for (i=index;i<strlength;i++) {for (; j<tmp_len;j++) {if (P_str[i]==str[j] ) break; if (J==tmp_len) break;//according to the condition of the inside for to jump out, find the end loop} if (I==strlength) re Turn npos;//not found,//based on the outside of the inner layer for the condition of judgment, to find that the end loop return i; } int mystring::find_first_not_of (const mystring& str,size_t index) {if (NULL = = str | | Index >=strlen GTH) return NPOs; size_t i=0,j=0; for (i=index;i<strlength;i++) {for (; j<str.strlength;j++) {if (p_str[i]== STR[J]) break;//If equal this round I is void, proceed to the next round if (j==str.strlength) break;//according to the condition of the inside for to jump out, find the end loop} if (I==strlength) Return npos;//not found,//based on the outside of the inside for the condition of judgment, to find that the end loop return i; } int mystring::find_first_not_of (const char ch,size_t index) {if (NULL = = CH | | index >=strlength) return NPOs; size_t i=0; for (i=index;i<strlength;i++) {if (p_str[i]!=ch)///with the above slightly different, find a range can break; } if (I==strlength) return npos;//not found,//based on the outside of the inside for the condition of the judge, found that the end loop return i; }
C + + string find_first_not_of source code