octave: Comparing Strings

 
 5.4 Comparing Strings
 =====================
 
 Since a string is a character array, comparisons between strings work
 element by element as the following example shows:
 
      GNU = "GNU's Not UNIX";
      spaces = (GNU == " ")
           ⇒ spaces =
             0   0   0   0   0   1   0   0   0   1   0   0   0   0
 
 To determine if two strings are identical it is necessary to use the
 ‘strcmp’ function.  It compares complete strings and is case sensitive.
 ‘strncmp’ compares only the first ‘N’ characters (with ‘N’ given as a
 parameter).  ‘strcmpi’ and ‘strncmpi’ are the corresponding functions
 for case-insensitive comparison.
 
  -- : strcmp (S1, S2)
      Return 1 if the character strings S1 and S2 are the same, and 0
      otherwise.
 
      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.
 
      *Caution:* For compatibility with MATLAB, Octave’s strcmp 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: Seestrcmpi XREFstrcmpi, Seestrncmp XREFstrncmp,
      Seestrncmpi XREFstrncmpi.
 
  -- : 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: Seestrncmpi XREFstrncmpi, Seestrcmp XREFstrcmp,
      Seestrcmpi XREFstrcmpi.
 
  -- : strcmpi (S1, S2)
      Return 1 if the character strings S1 and S2 are the same,
      disregarding case of alphabetic characters, and 0 otherwise.
 
      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.
 
      *Caution:* For compatibility with MATLAB, Octave’s strcmp function
      returns 1 if the character strings are equal, and 0 otherwise.
      This is just the opposite of the corresponding C library function.
 
      *Caution:* National alphabets are not supported.
 
      See also: Seestrcmp XREFstrcmp, Seestrncmp XREFstrncmp,
      Seestrncmpi XREFstrncmpi.
 
  -- : strncmpi (S1, S2, N)
      Return 1 if the first N character of S1 and S2 are the same,
      disregarding case of alphabetic characters, and 0 otherwise.
 
      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.
 
      *Caution:* For compatibility with MATLAB, Octave’s strncmpi
      function returns 1 if the character strings are equal, and 0
      otherwise.  This is just the opposite of the corresponding C
      library function.
 
      *Caution:* National alphabets are not supported.
 
      See also: Seestrncmp XREFstrncmp, Seestrcmp XREFstrcmp,
      Seestrcmpi XREFstrcmpi.