Navigation

Operators and Keywords

Function List:

C++ API

: strncmp (s1, s2, n)

Return 1 if the first n characters of strings s1 and s2 are the same, and 0 otherwise.

strncmp ("abce", "abcd", 3)
     ⇒ 1

If either s1 or s2 is a cell array of strings, then an array of the same size is returned, containing the values described above for every member of the cell array. The other argument may also be a cell array of strings (of the same size or with only one element), char matrix or character string.

strncmp ("abce", {"abcd", "bca", "abc"}, 3)
    ⇒ [1, 0, 1]

Caution: For compatibility with MATLAB, Octave’s strncmp function returns 1 if the character strings are equal, and 0 otherwise. This is just the opposite of the corresponding C library function.

See also: strncmpi, strcmp, strcmpi.

Package: octave