Compare Function

Compares two strings. If NLS is enabled, the result of this function depends on the current locale setting of the Collate convention.

Syntax

Compare (string1, string2  [ , justification ] )

string1, string2 are the strings to be compared.

justification is either L for left-justified comparison or R for right-justified comparison. If you do not specify L or R, L is the default. Any other value causes a runtime warning, and 0 is returned.

Remarks

The result of the comparison is returned as one of the following values:

-1 string1 is less than string2.

0 string1 equals string2 or the justification expression is not valid.

1 string1 is greater than string2.

Use a right-justified comparison for numeric strings; use a left-justified comparison for text strings. For mixed strings, take care. For example, a right-justified comparison of the strings AB100 and AB99 indicates that AB100 is greater than AB99 since 100 is greater than 99. But a right-justified comparison of the strings AC99 and AB100 indicates that AC99 is greater since C is greater than B.

Example

In the following example, the strings AB99 and AB100 are compared with the right-justified option, in which "AB100" is greater than "AB99":

On Compare("AB99", "AB100", "R") + 2 GoSub               
    LessThan,
    EqualTo 
    GreaterThan