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.

example

Note

The operator strncmp is not supported in Stateflow® charts that use C as the action language. For similar functionality, usestrcmp.

Examples

expand all

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);

Stateflow chart that uses the srtncmp operator in a state.

Input Arguments

expand all

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

Version History

Introduced in R2021b