string的find和find_first_of的区别
2017-07-30 09:18
1821 查看
今天遇到个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的字符。
现将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的字符。
相关文章推荐
- string中的find(),find_first_of(),find_first_not_of()之间区别
- string的find和find_first_of的区别
- string 中find_first_of()函数用法例题
- (转帖)如何将字符串前后的空白去除? (使用string.find_first_not_of, string.find_last_not_of) (C/C++)
- std::string 类中find_first_not_of ()函数
- string c++详解 find_first_not_of() find_first_of()
- find find_first_of区别
- C++中string.find()函数,string.find_first_of函数与string::npos
- string 类成员函数 find() / find_first_of() / find_last_of() 的用法详解
- string 搜索功能 find find_first_of
- string类中find() 函数 和find_first_of()函数的区别
- 如何将字符串前后的空白去除? (使用string.find_first_not_of, string.find_last_not_of) (C/C++)
- C++ 中string 的find与find_first_of 的区别?
- std :: string :: find_first_not_of
- 高德地图引入库错误std::string::find_first_of(char const*, unsigned long, unsigned long) const"
- C++填坑之std::string::find_first_of
- C++ 标准模板库学习之 string 类 详解 (一) 将一个句子中每个单词的单词字母顺序翻转 关于npos find_first_not_of find_first_of getline
- (原創) 如何将字符串前后的空白去除? (使用string.find_first_not_of, string.find_last_not_of) (C/C++)
- string类型中find和find_first_of
- string 中的 find()、 find_first_of()、find_first_not_of()