string-compare
The string-compare function (see screenshot below) returns the result of a character by character comparison of two input strings: string1 and string2. The comparison is based on the ASCII codes. Both string1 and string2 are of type xs:string. The function is case-sensitive. If the strings are equal, the result is 0. If string1 is less than string2, the result is -1. If string1 is greater than string2, the result is 1.
Example:
string1: hi
string2: Hit
The string-compare function compares the strings character by character. The comparison stops after the function has detected that the first character of string1 and the first character of string2 are different. The result is based on the comparison of the first character of each string. Since h is represented as a bigger ASCII code number (104 in the decimal system) than H (72 in the decimal system), string1 is greater than string2, and the result of the string comparison is 1. If the first character of string1 and the first character of string2 were the same, the function would proceed to analyze the second character and so on.
For simple string comparison with a boolean result, see core | logical functions | equal.
Languages
Built-in, C++, C#, Java.
Parameters
Name | Type | Description |
---|---|---|
string1 | xs:string | The first input string. |
string2 | xs:string | The second input string. |