关于String函数
1.常常忘記加string 頭文件
2.size和length函數沒有區別,length函數是為了增強可讀性
3.substr函數? s.substr(a,b)表示從a開始后的b位
s.substr();//返回s的全部內容 s.substr(11);//從索引11往后的子串 s.substr(5,6);//從索引5開始6個字符4.關于append函數和assign函數,append函數更偏向于添加,而assign更偏向于賦值。
s.append(5,'x')添加5個x;s.append(str,1,5)把str的1到5添加給s;
5.關于insert、erase函數
s.insert(0,”my name”);
? ? ? ?s.insert(1,str); s.erase(13);//從索引13開始往后全刪除 s.erase(7,5);//從索引7開始往后刪5個 6.關于find函數 ? 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相似,只不過是從后向前查找
?
轉載于:https://www.cnblogs.com/TYH-TYH/p/9425578.html
總結
以上是生活随笔為你收集整理的关于String函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux目录与文件常见处理命令
- 下一篇: BZOJ1598: [Usaco2008