|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
; Y; ^, j# Q5 C! K+ ^! l- V% E/ _0 i. l% ]; X7 W
如果需要全字符串匹配,用Find/ g" X( P7 G. J6 k
/ ?! W4 `4 I' l4 T( Z3 @
6 U* F! S) f( p今天遇到个bUG,原来是在查找子串时调用了find_first_of,导致字符串替换出现问题。
# g# S, `" {0 o. K% R; a& I/ ?9 G |# f8 o" Z
现将find和find_first_of的区别与几种使用形式介绍如下( r$ e) S7 M# [1 t" T& }
! [, D' }" h7 ]. l& ]8 [) q: u
find是查找子串,而find_first_of类似于模式匹配,只要与其中的一个字符匹配就行。
' s7 i2 J- G1 K% m/ I9 w9 }" o% J# a5 v# w) \
find有四种使用形式。. L- J% z) U% [- L3 Y, B: W& L
# i% `9 c2 G; q# Z9 |
1、size_type find(const basic_string& str, size_type pos = 0) const;* C8 v$ i' } t T4 _7 K( @- C% O9 s
6 j& T" ?+ \' c' |. D" M. L x, M! k表示 从pos位置开始找子字符串str( o0 f3 W- \1 C, `; U
: Z& l1 ]- }6 Q' A3 {8 z' ^2、size_type find(const char* s, size_type pos, size_type count)const;' P8 i: G2 J5 c4 H5 V. F
I- r' E2 r9 S" O: P6 C% z
从pos位置开始找到与字符串s的前count个字符相等的子串
' V, t% Q2 j K$ W9 R. a0 ~
1 P! R4 j! I; m% g G f1 O3、size_type find(const char* s, size_type pos = 0)const;9 u' F" J$ y1 F1 V7 m W& w5 a* v
. O* y6 I4 Q9 Z9 h# @5 ^$ s从pos位置开始找与字符串s相等的子串
4 G5 {$ s" H3 g4 a; v3 t2 c0 |( k* z8 y! }. ]
4、size_type find(char ch, size_type pos = 0) const;* X) Q; a! D) s/ m0 e! E( V1 P
% J2 N. a' V$ d c7 j' f# ^
从pos位置开始找字符ch。
' W5 z# m6 | T3 `
( I; f4 h0 [% u7 L/ k8 O0 ?3 o# x9 V7 R( ]' r7 d) l
, @; u* K( S$ y6 M8 m$ Q/ T
find_first_of的四种形式
" l" e' I; m! S. k9 n
0 X# ?; k3 A# x4 O1 Z1、size_type find_first_of(const basic_string& str, size_type pos = 0)const;
5 ~% O2 R( p# ~# {' o: w* E# I1 f$ g9 B& v5 {4 \& I
从pos位置开始找到第一个与str中任意一个字符相等的字符
+ b/ c4 f/ K0 b* n8 t2 s0 t, J+ K; }" Y J7 E
2、size_type find_first_of(const char*s, size_type pos, size_type count)const;$ E4 }' p2 w- D i1 r0 ^1 y9 K- |
4 H4 @( F8 K0 `* V) p从pos位置开始找到第一个与str的前count中的任意一个字符相等的字符! q" y( K( b/ h- u0 M' v
1 I+ o# V& N5 ]3、size_type find_first_of(const char* s, size_type pos = 0)const;( d) r* \ ?5 [& k0 x3 H. q
7 u4 t$ g7 D, {0 _) j' X从pos位置开始找到第一个与s中的任意一个字符相等的字符7 c# k: Z v' I4 \4 L) D8 e% F( @6 H
- o1 p$ ~+ c# E! `- _
4、size_type find_first_of(char ch, size_type pos = 0)const;
) r7 `" h- k' M* q1 o- k7 ~9 u) c# W. H3 [9 \
从pos位置开始找到第一个等于ch的字符。* A. q& ~& j6 ]4 W8 C' l$ S
9 o3 f' s3 m6 y: N
% v5 ~7 u8 n6 D. P# }; L) k9 s% j |
|