StrComp
From Xojo Documentation
This item was deprecated in version 2019r2. Please use String.Compare as a replacement. |
Makes a binary (case-sensitive) or text (lexicographic) comparison of the two strings passed and returns the result.
Usage
result = StrComp(string1, string2, mode)
Part | Type | Description |
---|---|---|
result | Integer | Returns the result of the comparison of string1 and string2.
The value can be -1, 0, or 1, according to the following rules: |
string1 | String | The first string for comparison. |
string2 | String | The second string for comparison. |
mode | Integer | The comparison mode, Binary or Text.
Mode can take on the following values: |
Enumeration
See the ComparisonOptions enumeration for values you can use with StrComp.
Notes
The text comparison is lexicographic, not case-insensitive. This means that case will be taken into account if the strings are the same (other than case).
When using Mode 0 (binary), StrComp always compares the bytes of the strings as they are, doing no encoding conversions. It's possible that two strings might look the same on screen but be reported as different in StrComp Mode 0 if they are in different encodings (and, therefore, contain different bytes).
Sample Code
The following code returns -1 because the two strings are the same in every way except in case:
The following code returns -1 because in a byte comparison of the two strings, string2 is greater than string1. The ASCII value of "S" is less than the ASCII value of "s".
This code compares two values lexicographically:
Var s2 As String = "Hello"
Var result As Integer
result = StrComp(s1, s2, REALbasic.StrCompLexical)
// result = 1