帮助中心帮助中心
(不推荐)在一个较长的字符串中查找另一个较短的字符串
不推荐使用 findstr。请改用 contains 或 strfind。
findstr
contains
strfind
k = findstr(str1,str2)
示例
k = findstr(str1,str2) 在两个输入参量中较长的那个参量中搜索较短的那个参量,并返回找到的每个实例的起始索引。如果找不到匹配的实例,则 findstr 返回空数组 []。输入参量 str1 和 str2 可以是字符向量或字符串标量。
str1,str2
[]
str1
str2
findstr 区分大小写。每个输入参量中的任何前导和尾随空白字符都显式包含在比较中。
与 contains 或 strfind 函数不同的是,findstr 的输入参量的顺序并不重要。如果您不确定两个输入参量中哪个更长,此函数会很有用。
全部折叠
创建一个字符串数组。使用 strmatch 和第三个输入 "exact" 来查找与文本 "max" 完全匹配的 strarray 元素。
strmatch
"exact"
"max"
strarray
strarray = ["max" "minimax" "maximum"]; x = strmatch("max",strarray,"exact")
x = 1
要比较的文本,指定为字符向量或字符串标量。strfind 在两个输入中较长的输入中搜索较短参量的所有实例。
数据类型: char | string
char
string
backgroundPool
ThreadPool
在 R2006a 之前推出
strfind | strtok | strcmp | strncmp | strcmpi | strncmpi | regexp | regexpi | regexprep | contains
strtok
strcmp
strncmp
strcmpi
strncmpi
regexp
regexpi
regexprep
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office