String class - comparison methods


5=5        ->     1          /* equal            */

42\=41     ->     1          /* All of these are */
42><41     ->     1          /* "not equal"      */
42<>41     ->     1

13>12      ->     1          /* Variations of    */
12<13      ->     1          /* less than and    */
13>=12     ->     1          /* greater than     */
12\<13     ->     0
12<=13     ->     1
12\>13     ->     1

All strict comparison operations have one of the characters doubled that define the operator. The == and \== operators check whether two strings match exactly. The two strings must be identical (character by character) and of the same length to be considered strictly equal.

The strict comparison operators such as >> or << carry out a simple character-by-character comparison. There is no padding of either of the strings being compared. The comparison of the two strings is from left to right. If one string is shorter than and a leading substring of another, then it is smaller than (less than) the other. The strict comparison operators do not attempt to perform a numeric comparison on the two operands.

For all the other comparison operators, if both terms are numeric, the String class does a numeric comparison (ignoring, for example, leading zeros— see ). Otherwise, it treats both terms as character strings, ignoring leading and trailing whitespace characters and padding the shorter string on the right with blanks.

Character comparison and strict comparison operations are both case-sensitive, and for both the exact collating order can depend on the character set. In an ASCII environment, the digits are lower than the alphabetic characters, and lowercase alphabetic characters are higher than uppercase alphabetic characters.

The strict comparison operators you can use in a message are:

String class - comparison methods


"space"=="space"     ->     1         /* Strictly equal     */

"space"\==" space"   ->     1         /* Strictly not equal */

"space">>" space"    ->     1         /* Variations of      */
" space"<<"space"    ->     1         /* strictly greater   */
"space">>=" space"   ->     1         /* than and less than */
"space"\<<" space"   ->     1
" space"<<="space"   ->     1
" space"\>>"space"   ->     1

Read Me - Common Public License V1.0 - Copyright Notice(©)

Comparison Methods


>>-comparison_operator(argument)-------------------------------><

Returns 1 (true) or 0 (false), the result of performing the specified comparison operation. The receiver object and the [argument] are the terms compared. Both must be string objects. If [argument] is not a string object, it is converted to its string representation for the comparison. The one exception is when [argument] is the Nil object for the ==, \==, =, \=, ><, and <> operators. A string object will never compare equal to the Nil object, even when the string matches the string value of the Nil object ("The Nil object"). As a result, == will always return 0 (false) when compared to the Nil object and \== will always return 1 (true). All of the relational comparisions (for example, <, >, <=, etc.) will always return .false when compared to the Nil object.

The comparison operators you can use in a message are:

= = methodof String class method=of String class True if the terms are equal (for example, numerically or when padded). False if argument is the Nil object.
\=, ><, <> >< methodof String class >< methodof String class <> methodof String class method\=of String class method><of String class method<>of String class True if the terms are not equal (inverse of =). True if argument is the Nil object.
> > method method> Greater than. False if argument is the Nil object.
< < method method< Less than. False if argument is the Nil object.
>= >= method method>= Greater than or equal to. False if argument is the Nil object.
\< \< method method\< Not less than. False if argument is the Nil object.
<= <= method method<= Less than or equal to. False if argument is the Nil object.
\> \> method method\> Not greater than. False if argument is the Nil object.
== == methodof String class method==of String class True if terms are strictly equal (identical)
\== \== method method\==of String class True if the terms are NOT strictly equal (inverse of ==)
>> >> method method>> Strictly greater than
<< << method method<< Strictly less than
>>= >>= method method>>= Strictly greater than or equal to
\<< \<< method method\<< Strictly NOT less than
<<= <<= method method<<= Strictly less than or equal to
\>> \>> method method\>> Strictly NOT greater than

Read Me - Common Public License V1.0 - Copyright Notice(©)