strcmp - Compare strings in Stateflow chart (case
sensitive) - MATLAB ([original](https://www.mathworks.com/help/stateflow/ref/strcmp.html)) ([raw](?raw))
Main Content
Compare strings in Stateflow chart (case sensitive)
Syntax
Description
`tf` = strcmp(`str1`,`str2`)
compares strings str1
and str2
.
- In charts that use MATLAB® as the action language, the operator returns
1
(true
) if the strings are identical and0
(false
) otherwise. - In charts that use C as the action language, the operator returns
0
if the strings are identical. Otherwise, it returns a nonzero integer that depends on the compiler that you use. This value can differ in simulation and generated code.
`tf` = strcmp(`str1`,`str2`,`n`)
compares the first n
characters in str1
andstr2
.
Note
This syntax is supported only in Stateflow® charts that use C as the action language. In charts that use MATLAB as the action language, use strncmp.
Examples
Return a value of 1
(true
) because the strings are equal.
x = strcmp("Hello","Hello");
Return a value of 0
(false
) because the strings are not equal.
y = strcmp("Hello","Hello!");
You can compare strings by using relational operators. Use==
to determine if two strings are equal.
Use ~=
to determine if two strings are not equal.
Return a value of 0
because the strings are equal.
x = strcmp("Hello","Hello");
Return a nonzero value because the strings are not equal.
y = strcmp("Hello","Hello!");
You can compare strings by using relational operators. Use==
to determine if two strings are equal.
Use !=
or ~=
to determine if two strings are not equal.
Return a value of 0
because the strings start with the same five characters.
z = strcmp("Hello","Hello!",5);
This syntax is supported only in Stateflow charts that use C as the action language. In charts that use MATLAB as the action language, use strncmp.
Input Arguments
Input strings, specified as string scalars. In charts that use MATLAB as the action language, enclose literal strings with double quotes.
Example: "Hello"
Number of characters checked, starting at the beginning of each string, specified as a positive integer.
Version History
Introduced in R2018b