Main Content


Compare first N characters of strings (case insensitive)



tf = strncmpi(str1,str2,n) compares the first n characters of str1 and str2, ignoring any differences in letter case. The operator returns 1 (true) if the strings are identical and 0 (false) otherwise.


The operator strncmpi is not supported in Stateflow® charts that use C as the action language.


expand all

Set x to 1 (true) because the first 13 characters in the strings match when you ignore case. Set y to 0 (false) because the first 14 characters in the strings do not match.

str1 = "Hello, world!";
str2 = "hello, World!!!!!!!!!!!!";
x = strncmpi(str1,str2,13);
y = strncmpi(str1,str2,14);

Stateflow chart that uses the srtncmpi 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.


Version History

Introduced in R2021b