std::string

1、substr( size_type off, size_type count ) 从源串中复制子串

#include <string>
//复制子串
std::string str1("新和xinbingcup");
std::string str_sub = str1.substr( 0, 4 );
//substr( size_type off, size_type count )
//off - 子串起始字符的位置,默认0  count - 子串长度,默认源串长度
//若count超过了父串长度,则子串将延续到源字符串的结尾

 

2、size_type find( char ch, size_type index )    size_type rfind( char ch, size_type index )

     返回源串中字符ch的位置

#include <string>
//size_type find( char ch, size_type index );  正序
//index是源串中查找的基准位置,从0开始数起,默认0
//返回从index开始从左往右第一个ch的位置,找不到返回std::string::npos
//size_type rfind( char ch, size_type index ); 逆序
//index是源串中查找的基准位置,从0开始数起,默认源串长度
//返回从index开始从右往左第一个ch的位置,找不到返回std::string::npos
//std::string::npos 是一个常数,用来表示不存在的位置,一般是-1
std::string str1("xinbingicup");
int rr = str1.rfind('i');//7
int tt = str1.find('i');//1
int o = std::string::npos;//-1

 

转载于:https://www.cnblogs.com/thinknothing/p/3966103.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值