matlab中这两个字符串查找的函数findstr(), strfind()表明上看起来用法相似,效果也相似。
1. findstr(s1,s2)--在较长的字符串中查找较短的字符串出现的次数,并返回其位置,因此无论s1,s2哪个为长字符串,位置在前在后都没有关系。
例:
s = 'Find the starting indices of the shorter string.';
findstr(s, 'the')
ans =
findstr('the', s)
ans =
2. strfind(s1,s2)--or strfind(s1,pattern),因此其意思在s1中搜索pattern,
例:
S = 'Find the starting indices of the pattern string';
strfind(S, 'in')
ans =
strfind(S, 'In')
ans =
本文详细介绍了Matlab中findstr()和strfind()两个字符串查找函数的区别与用法,通过实例展示了如何在不同场景下正确使用这两个函数。
4856

被折叠的 条评论
为什么被折叠?



