Asp.net c ++ string search code

Source: Internet
Author: User

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;
    }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.