strncmp - Compare first N characters of strings in Stateflow chart
(case sensitive) - MATLAB ([original](https://www.mathworks.com/help/stateflow/ref/strncmp.html)) ([raw](?raw))
Main Content
Compare first N characters of strings in Stateflow chart (case sensitive)
Since R2021b
Syntax
Description
`tf` = strncmp(`str1`,`str2`,`n`)
compares the first n
characters of str1
andstr2
. The operator returns 1
(true
) if the strings are identical and 0
(false
) otherwise.
Note
The operator strncmp
is not supported in Stateflow® charts that use C as the action language. For similar functionality, usestrcmp.
Examples
Set x
to 1
(true
) because the first 13 characters in the strings match. Set y
to0
(false
) because the first 14 characters in the strings do not match.
str1 = "Hello, world!"; str2 = "Hello, world!!!!!!!!!!!!"; x = strncmp(str1,str2,13); y = strncmp(str1,str2,14);
Input Arguments
Input strings, specified as string scalars. Enclose literal string with double quotes.
Example: "Hello"
Number of characters checked, starting at the beginning of each string, specified as a positive integer.
Limitations
- This operator does not support the use of Stateflow structure fields or messages. For more information about structures in Stateflow, see Access Bus Signals.
Version History
Introduced in R2021b