<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>
string一些常用函数基础
最新推荐文章于 2020-06-22 10:50:33 发布