string的find和find_first_of的区别

今天遇到个bug,原来是在查找子串时调用了find_first_of,导致字符串替换出现问题。

现将find和find_first_of的区别与几种使用形式介绍如下

find是查找子串,而find_first_of类似于模式匹配,只要与其中的一个字符匹配就行。

find有四种使用形式。

1、size_type find(const basic_string& str, size_type pos = 0) const;

表示 从pos位置开始找子字符串str

2、size_type find(const char* s, size_type pos, size_type count)const;

从pos位置开始找到与字符串s的前count个字符相等的子串

3、size_type find(const char* s, size_type pos = 0)const;

从pos位置开始找与字符串s相等的子串

4、size_type find(char ch, size_type pos = 0) const;

从pos位置开始找字符ch。


find_first_of的四种形式

1、size_type find_first_of(const basic_string& str, size_type pos = 0)const;

从pos位置开始找到第一个与str中任意一个字符相等的字符

2、size_type find_first_of(const char*s, size_type pos, size_type count)const;

从pos位置开始找到第一个与str的前count中的任意一个字符相等的字符

3、size_type find_first_of(const char* s, size_type pos = 0)const;

从pos位置开始找到第一个与s中的任意一个字符相等的字符

4、size_type find_first_of(char ch, size_type pos = 0)const;

从pos位置开始找到第一个等于ch的字符。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值