MATLAB Function Reference
  Go to function:
    Search    Help Desk 
strcmp    Examples   See Also

String compare

Syntax

Description

k = strcmp(str1,str2) compares the strings str1 and str2 and returns logical true (1) if the two are identical, and logical false (0) otherwise.

TF = strcmp(S,T) where either S or T is a cell array of strings, returns an array TF the same size as S and T containing 1 for those elements of S and T that match, and 0 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 strcmp function is case sensitive. When comparing a string array to a cell or cell array, the string array is deblanked (trailing spaces are removed) before comparison. However, when comparing a scalar string (a string array with only one row) to a cell or cell array, the scalar string is not deblanked. Use deblank to eliminate any trailing blanks in the scalar string before comparison.

Examples

These examples show the comparison of two strings:

This example compares a string to a cell array of strings:

These examples compare two cell arrays of strings:

These examples demonstrate scalar expansion:

This example compares a scalar string to a cell:

See Also

findstr, strcmpi, strmatch, strncmp



[ Previous | Help Desk | Next ]