Text Comparison
In this example, let's look at how to compare text fragments represented as string arrays.
Comparing strings for equality
You can compare arrays of strings for equality using the relational operators == and !=. When you compare arrays of strings, the output is a logical array in which 1 (true) is true, and 0 (false) is incorrect.
str1 = "Hello";
str2 = "World";
str1,str2
str1 != str2
str1 = ["Mercury" "Gemini" "Apollo";"Skylab" "Skylab B" "International Space Station"];
str2 = "Apollo";
str1 .== str2
str2 = ["Mercury" "Mars" "Apollo";"Jupiter" "Saturn" "Neptune"];
str1 .!= str2
Comparing strings with other relation operators
You can also compare strings using the relation operators >, >=, < and <=. Lines starting with uppercase letters precede lines starting with lowercase letters. For example, the string "ABC" is smaller than "abc". Numbers and some punctuation marks are also placed before letters.
"ABC" < "abc"
Compare an array of strings containing names with another name using the > operator. The names Sanchez, de Ponte, and Nash come after Matthews because S, d, and N are all larger than M.
str = ["Sanchez","Jones","de Ponte","Crosby","Nash"];
TF = (str .> "Matthews")
There is also a function cmp(), which compares two strings. Returns 0 if they are equal, 1 when the first string argument is greater than the second, and -1 when the first argument is less than the second, respectively.
cmp("ABC","abc")
In this article, functions for performing text comparison in string arrays were considered. For more information about working with text and string arrays, see the sections: Text strings and Arrays