Forward and reverse lookup of the string class

Source: Internet
Author: User

1. forward and reverse lookup Functions

Forward search: S. Find (S0)

Reverse lookup: S. rfind (S0)

S indicates the string to be searched, and S0 indicates the substring to be searched. The return values of both functions are the values

The position of the first character in the original string to be searched.

2. Example:

# Include <iostream>
# Include <string>
Using namespace STD;
Int main (){
Int P0, P1;
String S = "abcdabcefabc ";
String S0 = "ABC ";
P0 = S. Find (S0 );
P1 = S. rfind (S0 );
Cout <"P0:" <P0 <Endl; // output result 0
Cout <"P1:" <P1 <Endl; // output result 9
Return 0;
}

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.