Compares two String expressions either taking into consideration or ignoring the case of the characters and returns an indication of the results.
...String.Compare( string_a, string_b, ignore_case )
Prerequisites
None
Parameters
string_a
A required String expression. The String expression can be a String variable, constant, function or method, or a concatenation of these String elements.
string_b
A required String expression. The String expression can be a String variable, constant, function or method, or a concatenation of these String elements.
ignore_case
An optional numeric expression. If the value of this expression is True, the comparison is performed ignoring the case of the characters, i.e. "A" will be equal to "a". If this value is False or not specified, the comparison is performed in a case-sensitive manner.
Remarks
This shared method compares the values of two String expressions and returns an indication of the results of the comparison. Depending upon the value of ignore_case, the comparison is either performed taking into account the case of characters or ignoring the case of characters. The returned value is interpreted as shown in Table 19-97.
String Relationship | Returned result |
---|---|
string_a > string_b |
> 0 |
string_a = string_b |
= 0 |
string_a < string_b |
< 0 |
String comparisons can also be performed using the standard comparison operators, i.e. =, <>, <, >, <=, >=. When two Strings are compared using the comparison operators, the comparison is always performed taking into consideration the case of the characters.
Examples
Dim stg As String ' Create a new string variable
Dim ii As Integer
stg = "aBcdef"
ii = String.Compare(stg, "abcdef") ' ii will be set <0
See Also