[C ++] string-type lookup Functions

Source: Internet
Author: User

[C ++] string-type lookup Functions

String-type lookup function: int find (char c, int pos = 0) const; // start from pos to find the position of character c in the current string int find (const char * s, int pos = 0) const; // start from pos to find the position of string s in the current string int find (const char * s, int pos, int n) const; // start from pos to find the position of the First n characters in string s in the current string int find (const string & s, int pos = 0) const; // start from pos to find the position of string s in the current string // return the position when the query is successful. If the query fails, return the string: npos value int rfind (char c, int pos = npos) const; // search for the position of character c in the current string from the back to the back of the pos (const char * s, Int pos = npos) const; int rfind (const char * s, int pos, int n = npos) const; int rfind (const string & s, int pos = npos) const; // start from the pos and start from the back to the front to find the position of the string consisting of the First n characters in string s in the current string. The position of the string is returned successfully. If the position fails, the string is returned :: npos value int find_first_of (char c, int pos = 0) const; // search for the position where character c appears for the first time from pos int find_first_of (const char * s, int pos = 0) const; int find_first_of (const char * s, int pos, int n) const; int find_first_of (const string & s, I Nt pos = 0) const; // start from pos to find the position of the first character in the array of the First n characters in s in the current string. String: npos int find_first_not_of (char c, int pos = 0) const; int find_first_not_of (const char * s, int pos = 0) const; int find_first_not_of (const char * s, int pos, int n) const; int find_first_not_of (const string & s, int pos = 0) const; // find the position of the first character not in string s from the current string, and return string: npos int find_last_of (char c, int pos = npos) const; int find_last_of (const char * s, int pos = npos) const; int find_last_of (const char * s, int pos, int n = npos) const; int find_last_of (const string & s, int pos = npos) const; int find_last_not_of (char c, int pos = npos) const; int find_last_not_of (const char * s, int pos = npos) const; int find_last_not_of (const char * s, int pos, int n) const; int find_last_not_of (const string & s, int pos = npos) const; // find_last_of and find_last_not_of are similar to find_first_of and find_first_not_of, but they are searched forward from the back.

An example is attached below:

#include
  
   #include
   
    using namespace std;void main(){    string a="0AA00AA00";    char str[]="AA";    int pos=a.find(str,2);    cout<
    
   
  

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.