C++字符及字符串处理函数

来源:互联网 发布:adobe premier mac 编辑:程序博客网 时间:2024/05/20 19:16


1. find_first_of(char c, int start )
查找字符串中第1个出现的c,由位置start开始。如果有匹配,则返回匹配位置;否则,返回-1. 默认情况下,start为0,函数搜索整个字符串。
2. find_last_of(char c )
查找字符串中最后1个出现的c ,从末尾开始。如果有匹配,则返回匹配位置;否则,返回-1。


3.提取字符子串 string substr(int start=0,int count= -1)
 从起始位置开始复制字符串中的count 个字符,并返回这些字符作为子串。
      如果字符串尾部小于count字符或者count 为-1,提取start之后的整个尾子串。
      如果[color=#FF0000]省略count[/color],substr(int start=0)提取start之后整个尾子串
4. int find(const string& s,int start = 0)
   在字符串中查找指定模式。该函数将字符串s和位置start作为参数,并查找 s的匹配作为子串
     如果有匹配,则返回匹配的位置;否则返回-1。默认情况下,start为0,函数搜索整个字符串
5. void insert(int start, const string& s):
               将子串s放入字符串中,起始于位置start。插入操作增加了原始字符串的长度。
5. void erase(int start, int count)
    如果count=-1或者 count大于尾子串长度,删除整个尾子串,默认情况下start=0,count=-1;


6. char *c_str();
         返回一个等价于字符串对象的c语言风格字符串的地址;将字符串对象转换为c语言风格字符串
0 0
原创粉丝点击