常用字符串

string

string erase(int pos = 0, int n = 长度);

//删除pos开始的n个字符,返回修改后的字符串
str.erase(0,n)
在这里插入图片描述
string insert(int p0,const string &s, int pos, int n);
//在p0位置插入字符串s中pos开始的前n个字符

string insert(int p0,const string &s);

注意参数是字符串
str.insert(0,“love”)

string substr(int pos = 0,int n = 长度);

str.substr(0,4)

int find(char c, int pos = 0) ;

//从pos开始查找字符c在当前字符串的位置,参数可有可无

int find(const char *s, int pos = 0) const;

//从pos开始查找字符串s在当前串中的位置
查找成功时返回所在位置,失败返回string::npos的值
int find_first_of(char c, int pos = 0) const;//从pos开始查找字符c第一次出现的位置
int find_first_of(const char *s, int pos = 0) const;
int find_last_of(char c, int pos = npos) const;
int find_last_of(const char *s, int pos = npos) const;

string replace(int p, int n,const char *s);

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值