添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Working with a string array is different than working with a char array. What Walter wrote is true for char arrays (which was the main data type for storing text data in 2011, as the string class didn't exist yet.)
button = "button" ;
str = 'abcde' ;
if contains(str, button)
disp( "[" + str + "] contains the string [" + button + "]" )
else
disp( "[" + str + "] doesn't contain the string [" + button + "]" )
end
Now change the contents of the str variable and perform the same comparison.
str = 'space button' ;
if contains(str, button)
disp( "[" + str + "] contains the string [" + button + "]" )
else
disp( "[" + str + "] doesn't contain the string [" + button + "]" )
end
The contains function can accept two char vectors, two string arrays, two cell arrays containing char vectors, or a combination of those three types.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!