您的位置:首页 > 其它

string一些常用函数基础

2015-08-05 09:53 113 查看
<span style="font-size:18px;">string  str("hello world");
str.insert (pos,"hello world");
str.erase (pos,len);
str1.replace (pos,len,args);
str.find ("hello world");//在str中查找"wo" 第一次出现的位置的下标。
str.rfind ("hello world"); //在str中查找"wo"最后一次出现位置的下标
str.find_first_of (args);    //在str中查找args的任意字符的第一次出现。
str.find_last_of (args);     //在str中查找args的任意字符的最后一次出现。
str.find_first_no_of (args);  //在str中查找第一个不属于 args的字符。
str.find_last_no_of (args);   //在str中查找最后一个不属于 args的字符。
string 类的find方法的返回值都是size_type 类型。
当没有查到时,返回值是string::npos;可以将返回值和string::nops比较,判断是否找到。
从字符串中截取子串:   (截取子串substr )
string  str("hello world");
str.substr(pos,n);  //截取下标从pos开始,长度为n的一个子串。
str.substr(pos);   //截取下标从pos开始到字符串末尾的子串。</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: