C++ string类型成员函数

find()函数的功能是从std::string对象的头部顺序查找目标值,如果找到返回该目标值出现的位置,如果没有在字符串对象中找到目标对象,返回值为string::npos(==-1):
    (1) size_type find(charT c, size_type pos = 0) const;

         查找字符c在字符串中的位置,并返回该位置基于0的索引值,它是从pos开始查找的。

    (2) size_type find(const charT *cs, size_type pos = 0) const;

         查找字符串cs在字符串中出现的位置,并返回该位置基于0的索引值,它是从pos开始查找的。

    (3) size_type find(const charT *cs, size_type pos, size_type n = npos) const;

         查找字符串cs前n个子串在字符串中出现的位置,并返回该位置基于0的索引值,它是从pos开始查找的。
    (4) size_type find(const basic_string &str, size_type pos = 0) const;

         查找字符串str在字符串中出现的位置,并返回该位置基于0的索引值,它是从pos开始查找的。

   

rfind()函数的功能是从std::sring对象的尾部反向查找目标值,如果找到返回该目标值出现的位置,如果没有
在字符串对象中找到目标对象,返回值为string::npos(-1):

    (1) size_type rfind(charT c, size_type pos = npos) const;

         反向查找字符c在字符串中出现的位置,并返回该位置基于0的索引值。
    (2) size_type rfind(const charT *cs, size_type pos = npos) const;

         反向查找以字符串cs在字符串中出现的位置,并返回该位置基于0的索引值。
    (3) size_type rfind(const charT *cs, size_type pos, size_type n = npos) const;

         反向查找字符串cs前n个子串在字符串中出现的位置,并返回该位置基于0索引值,它是从pos开始查找的。

    (4) size_type rfind(const basic_string &str, size_type pos = npos) const;

         反向查找字符串str在字符串中出现的位置,并返回该位置基于0的索引值,它是从pos开始查找的。

 

find_first_of()函数的功能是在string对象中查找参数字符/字符串中的任一字符,如果找到匹配的字符,则返回第一个匹配字符的位置--该位置是基于0的索引值,否则,返回string::npos(==-1)。查找是从pos位置开始的:

    size_type find_first_of( charT c, size_type pos = 0 ) const;

    size_type find_first_of( const charT* cs, size_type pos = 0 ) const;

    size_type find_first_of( const charT* cs, size_type pos, size_t n ) const;

    size_type find_first_of( const string& str, size_type pos = 0 ) const;

 

find_first_not_of()函数的功能是在string对象中查找参数字符/字符串外的任一字符,如果找到匹配的字符,则返回第一个匹配字符的位置--该位置是基于0的索引值,否则,返回string::npos(==-1)。查找是从pos位置开始的:

    size_type find_first_not_of(charT c, size_type pos = 0) const;
    size_type find_first_not_of(const charT  *cs, size_type pos = 0) const;

    size_type find_first_not_of(const charT  *cs, size_type pos, size_type n) const;

    size_type find_first_not_of(const basic_string &str, size_type pos = 0) const;
    

    size_t find_last_of( const string& str, size_t pos = npos ) const;
    size_t find_last_of( const char* s, size_t pos, size_t n ) const;
    size_t find_last_of( const char* s, size_t pos = npos ) const;
    size_t find_last_of( char c, size_t pos = npos ) const;

 

    size_t find_last_not_of( const string& str, size_t pos = npos ) const;
    size_t find_last_not_of( const char* s, size_t pos, size_t n ) const;
    size_t find_last_not_of( const char* s, size_t pos = npos ) const;
    size_t find_last_not_of( char c, size_t pos = npos ) const;
    
                                                    std::string类的插入函数: 

string &insert(int pos, const char *s);                         //在pos位置插入字符串s中pos开始的前n个字符
string &insert(int pos, const char *s, int n);                //在pos位置插入字符串s中pos开始的前n个字符
string &insert(int pos,const string &s);                       //在pos位置插入字符串s中pos开始的前n个字符
string &insert(int pos,const string &s, int pos, int n); //在pos位置插入字符串s中pos开始的前n个字符
string &insert(int pos, int n, char c);                          //在pos处插入n个字符c
iterator insert(iterator it, char c);                               //在it处插入字符c,返回插入后迭代器的位置
void insert(iterator it, const_iterator first, const_iterator last);//在it处插入[first,last)之间的字符
void insert(iterator it, int n, char c);                            //在it处插入n个字符c

 

                                                      std::string类的追加函数:

string &operator+=(const string &s);   //把字符串s连接到当前字符串的结尾 
string &append(const char *s);            //把c类型字符串s连接到当前字符串结尾
string &append(const char *s,int n);    //把c类型字符串s的前n个字符连接到当前字符串结尾
string &append(const string &s);         //同operator+=()
string &append(const string &s,int pos,int n);//把字符串s中从pos开始的n个字符连接到当前字符串的结尾
string &append(int n,char c);               //在当前字符串结尾添加n个字符c
string &append(const_iterator first,const_iterator last);//把迭代器first和last之间的部分连接到当前字符串的结尾

 

                                                     std::string类的删除函数: 

iterator erase(iterator first, iterator last);  //删除[first,last)之间字符,返回删除后迭代器位置
iterator erase(iterator it);                         //删除it指向的字符,返回删除后迭代器的位置
string &erase(int pos = 0, int n = npos);  //删除pos开始的n个字符,返回修改后的字符串

 

                                                      std::string类的替换函数: 

string &replace(int pos, int n,const char *s);         //删除pos开始的n个字符,然后在pos处插入串s
string &replace(int pos, int n,const char *s, int n);//删除pos开始的n个字符,然后在pos处插入串s的前n个字符
string &replace(int pos, int n,const string &s);      //删除pos开始的n个字符,然后在pos处插入串s
string &replace(int pos, int n,const string &s, int pos, int n); //删除pos开始的n个字符,然后在pos处插入串s中从                                                                                                pos开始的n个字符

string &replace(int pos, int n,int n, char c);           //删除pos开始的n个字符,然后在pos处插入n个字符c
string &replace(iterator first, iterator last,const char *s);//把[first0,last0)之间部分替换为字符串s
string &replace(iterator first, iterator last,const char *s, int n);//把[first,last)之间部分替换为s的前n个字符
string &replace(iterator first, iterator last,const string &s);       //把[first,last)之间部分替换为串s
string &replace(iterator first, iterator last,int n, char c);            //把[first,last)之间的部分替换为n个字符c
string &replace(iterator first0, iterator last0,const_iterator first1, const_iterator last1);//把[first0,last0)之间部                                                                                                  分替换成[first1,last1)之间的字符串

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值