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.
Find the treasures in MATLAB Central and discover how the community can help you!