strcmp
Compare strings
Syntax
Description
compares tf
= strcmp(s1,s2
)s1
and s2
and
returns 1
(true
) if the two
are identical and 0
(false
)
otherwise. Text is considered identical if the size and content of
each are the same. The return result tf
is of data
type logical
.
The input arguments can be any combination of string arrays, character vectors, and cell arrays of character vectors.
Examples
Input Arguments
Output Arguments
Tips
The
strcmp
function is intended for comparison of text. If used on unsupported data types,strcmp
always returns0
.For case-insensitive text comparison, use
strcmpi
instead ofstrcmp
.Although
strcmp
shares a name with a C function, it does not follow the C language convention of returning0
when the text inputs match.With string arrays, you can use relational operators (
==
,~=
,<
,>
,<=
,>=
) instead ofstrcmp
. You can compare and sort string arrays just as you can with numeric arrays.
Extended Capabilities
Version History
Introduced before R2006a