string類的查詢函式

2021-06-22 04:27:58 字數 1898 閱讀 2676

string類的查詢函式:

int find(char c, int pos = 0) const;//從pos開始查詢字元c在當前字串的位置

int find(const char *s, int pos = 0) const;//從pos開始查詢字串s在當前串中的位置

int find(const char *s, int pos, int n) const;//從pos開始查詢字串s中前n個字元在當前串中的位置

int find(const string &s, int pos = 0) const;//從pos開始查詢字串s在當前串中的位置

//查詢成功時返回所在位置,失敗返回string::npos的值

int rfind(char c, int pos = npos) const;//從pos開始從後向前查詢字元c在當前串中的位置

int rfind(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;

//從pos開始從後向前查詢字串s中前n個字元組成的字串在當前串中的位置,成功返回所在位置,失敗時返回string::npos的值

int find_first_of(char c, int pos = 0) const;//從pos開始查詢字元c第一次出現的位置

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,int pos = 0) const;

//從pos開始查詢當前串中第乙個在s的前n個字元組成的陣列裡的字元的位置。查詢失敗返回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;

//從當前串中查詢第乙個不在串s中的字元出現的位置,失敗返回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和find_last_not_of與find_first_of和find_first_not_of相似,只不過是從後向前查詢

String類的方法查詢

string類中有很多的常用的方法,我們在學習乙個類的時候,不要盲目的把所有的方法嘗試去使用一遍,這時我們應該根據這個物件的特點分析這個物件應該具備那些功能,這樣大家應用起來更方便。字串是乙個物件,那麼它的方法必然是圍繞操作這個物件的資料而定義的。我們想想字串中有哪些功能呢?1.字串中有多少個字元?...

關於C 中string類的查詢函式的說明

int find char c,int pos 0 const 從pos開始查詢字元c在當前字串的位置 int find const char s,int pos 0 const 從pos開始查詢字串s在當前串中的位置 int find const char s,int pos,int n cons...

string類擴充套件函式

獲取字串對應的位元組數 string.prototype.getbyte function 擷取字串長度 string.prototype.substring function len,bt,aso else if charlen len else str chars if aso else ret...