MATLAB Function Reference Previous page   Next Page
strncmp

Compare first n characters of strings

Syntax

Description

k = strncmp('str1', 'str2', n) returns logical 1 (true) if the first n characters of the strings str1 and str2 are the same, and returns logical 0 (false) otherwise. Arguments str1 and str2 can also be cell arrays of strings.

TF = strncmp(S, T, N), where either S or T is a cell array of strings, returns an array TF the same size as S and T containing logical 1 (true) for those elements of S and T that match (up to n characters), and logical 0 (false) otherwise. S and T must be the same size (or one can be a scalar cell). Either one can also be a character array with the right number of rows.

Remarks

The command strncmp is case sensitive. Any leading and trailing blanks in either of the strings are explicitly included in the comparison.

strncmp is intended for comparison of character data. When used to compare numeric data, strncmp returns logical 0.

See Also

strncmpi, strcmp, strcmpi, strmatch, strfind, findstr, regexp, regexpi, regexprep


Previous page  strmatch strncmpi Next page

© 1994-2005 The MathWorks, Inc.