string find和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_first_of和find_last_of是部分匹配。
utf-8 “平” E5 B9 B3
"一蓑烟雨任平生。" E4 B8 80 E8 93 91 E7 83 9F E9 9B A8 E4 BB BB E5 B9 B3 E7 94 9F E3 80 82
因为部分匹配,所以一个前一个后

posted @ 2020-10-12 06:58  乘于时  阅读(590)  评论(0编辑  收藏  举报