c++ string find(), rfind(), find_first_of(),find_last_of()
2021-04-18 21:26
                         标签:const   end   pre   bsp   npos   last   函数   反转字符串   air    函数原型:       输入:hello     c++ string find(), rfind(), find_first_of(),find_last_of() 标签:const   end   pre   bsp   npos   last   函数   反转字符串   air    原文地址:https://www.cnblogs.com/r1-12king/p/13293305.htmlfind(), rfind()
int find(const string& str, int pos = 0) const; //查找str第一次出现位置,从pos开始查找
int find(const char* s, int pos = 0) const; //查找s第一次出现位置,从pos开始查找
int find(const char* s, int pos, int n) const; //从pos位置查找s的前n个字符第一次位置
int find(const char c, int pos = 0) const; //查找字符c第一次出现位置
int rfind(const string& str, int pos = npos) const; //查找str最后一次位置,从pos开始查找
int rfind(const char* s, int pos = npos) const; //查找s最后一次出现位置,从pos开始查找
int rfind(const char* s, int pos, int n) const; //从pos查找s的前n个字符最后一次位置
int rfind(const char c, int pos = 0) const; //查找字符c最后一次出现位置
find_first_of(),
find_last_of()
例题:leetcode 345题:反转字符串中的元音字母
返回:holleclass Solution {
public:
    string reverseVowels(string s) {
        int left=0,right=s.size()-1;
        while(leftright)
        {
            left=s.find_first_of("aeiouAEIOU",left);
            right=s.find_last_of("aeiouAEIOU",right);
            if(leftright)
            {
                swap(s[left++],s[right--]);
            }
        }
        return s;
    }
};
上一篇:哪些人需要学习Python开发?
下一篇:字符串与字符数组的多种转换方式。
文章标题:c++ string find(), rfind(), find_first_of(),find_last_of()
文章链接:http://soscw.com/index.php/essay/76369.html