Main Content

strncmp

Compare first N characters of strings in Requirements Table block (case sensitive)

Since R2022b

Description

example

tf = strncmp(str1,str2,n) compares up to n characters of str1 and str2. The operator returns 1 (true) if the strings are identical and 0 (false) otherwise. Use this operator in the Requirements Table block.

Examples

expand all

In a Requirements Table block, create a requirement that checks if the string "Hello, world!" matches the first thirteen characters of the string "Hello, world!!!!!!!!!!!!".

y = strncmp("Hello, world!","Hello, world!!!!!!!!!!!!",13)

This example shows a requirement that checks if the string "Hello, world!" matches the first 13 characters of the string "Hello, world!!!!!!!!!!!!".

Input Arguments

expand all

Input strings, specified as string scalars. Enclose literal string with double quotes.

Example: "Hello"

Data Types: string

Number of characters checked, starting at the beginning of each string, specified as a positive integer.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Limitations

  • This operator does not support the use of Simulink.Bus object fields.

Version History

Introduced in R2022b