You are here: Function Reference > Alphabetical Listing > S > STRCompare

STRCompare

Use this function to compare two strings with case a consideration. In normal DAL string expressions, strings are compared in a case-insensitive manner. For example, the system would normally evaluate the following strings to be equal:

ABC abc

If, however, you use the STRCompare function, the system considers case and judges these strings to not be equal.

Note The best way to use this function is to test for equality. For instance, use this function to test two strings and compare for a zero (0) value being returned to indicate the strings are equal or a non-zero value to indicate they are unequal.
Note You can use this function to determine if one string is greater or less than the other, but the result can be confusing if the strings contain mixed case or have different lengths.

Syntax

STRCompare (String1, String2, #Count)

Parameter

Description

String1

Enter the text for the first string you want to compare. The default is an empty string.

String2

Enter the text for the second string you want to compare. The default is an empty string.

#Count

(Optional) Enter the number of characters to compare.

If you enter a value greater than zero, the system compares that number of characters.

If you enter zero (0) or less, the system compares all characters.

If you enter a value greater than the length of either string, the system pads the strings with blank characters to match the number of characters you specified.

The default is -1 which indicates that all characters will be compared.

If String1 and String2 compare as equal, the system returns a zero (0).

The system returns a negative one (-1) if String1 is less than String2.

The system returns a one (1) if String1 is greater than String2.

Example

Assume String1 is ABCDEF and String2 is ABCdef in these examples:

This example

Returns

#RTN = STRCompare( string1 , string2 )

-1

#RTN = STRCompare( string2 , string1 )

1

#RTN = STRCompare( string1 , string2 , 3 )

0

See also