Asp tutorial. net c ++ string search code
Search for the string deststr in the string srcstr. If it is found, the return value of the string deststr in the string srcstr
Location.
# Include <string>
# Include <iostream>
# Include <algorithm>
Using namespace std;
Bool nocase_compare (char c1, char c2)
{
Return toupper (c1) = toupper (c2 );
}
Int main ()
{
String s1 ("This is a string ");
String s2 ("STRING ");
// Compare case insensitive
If (s1.size () = s2.size () & // ensure same sizes
Equal (s1.begin (), s1.end (), // first source string
S2.begin (), // second source string
Nocase_compare) {// comparison criterion
Cout <"the strings are equal" <endl;
}
Else {
Cout <"the strings are not equal" <endl;
}
// Search case insensitive
String: iterator pos;
Pos = search (s1.begin (), s1.end (), // source string in which to search
S2.begin (), s2.end (), // substring to search
Nocase_compare); // comparison criterion
If (pos = s1.end ()){
Cout <"s2 is not a substring of s1" <endl;
}
Else {
Cout <'"' <s2 <" "is a substring ""
<S1 <"(at index" <pos-s1.begin () <")"
<Endl;
}
}