Method Reference: string.strcmp

string: TF = strcmp (A, B)

Compare strings.

TF is true, if string A is lexicographically equal to B. If one input is a string array, the other input can be a string array, a character vector, or a cell array of character vectors.

If either A or B is a string array or a cell array of character vectors, then a logical array TF of the same size is returned, containing the values described above for every member of the array. In this case, the other argument may also be a string array or a cell array of character vectors (of the same size or scalar), or a character vector.

Source Code: string

Example: 1

strcmp compares strings for exact equality — the same idea as ==, kept for compatibility with the classic string functions.

 a = string ({'cat'; 'dog'})
a =
  2x1 string array

    "cat"    
    "dog"
 strcmp (a, 'cat')
ans =

  1
  0