Difference between revisions of "String.Compare"

From Xojo Documentation

(Created page with "N/A")
 
Line 1: Line 1:
N/A
+
{{MethodBox
 +
| name = Compare
 +
| ownertype = class
 +
| scope = public
 +
| parameters = other As [[String]], Optional options As [[Integer]] = 0, Optional locale As [[Locale]] = Nil
 +
| owner = [[String]]
 +
| returntype = [[Integer]]
 +
}}
 +
{{Description | text = Compares a text value with another text value. A non-empty text is always greater than an empty text. By default, a case-insensitive comparison is done. Returns a negative integer if the value is less than other, 0 if the two values are equal, and a positive integer if the value is greater than other.}}
 +
 
 +
== Parameters ==
 +
{| class="genericTable"
 +
! width=25% | Parameter
 +
! width=50% | Description
 +
|-
 +
| other
 +
| The [[String]] to compare with the original [[String]].
 +
|-
 +
| options
 +
| (Optional) Comparison options.  Use constant CompareCaseSensitive for case-sensitive comparisons.
 +
|-
 +
| locale
 +
| (Optional) The locale to use for comparisons. By default an invariant locale (not dependent on the system settings) is used.
 +
|-
 +
|}
 +
 
 +
== Notes ==
 +
By default this performs a case-insensitive comparison. To do a case-sensitive comparison, supply the CompareCaseSensitive constant to the options parameter.
 +
 
 +
By default comparisons are done in an invariant locale (i.e. not dependent on the user's preferences). The locale parameter can be used to specify an explicit locale to do comparisons in.
 +
 
 +
== Exceptions ==
 +
* [[RuntimeException]] when the specified options are invalid.
 +
 
 +
== Sample Code ==
 +
Compare two String values:
 +
<rbcode>
 +
Var dog As String = "Dog"
 +
Var cat As String = "Cat"
 +
 
 +
Var result As Integer
 +
result = dog.Compare(cat)
 +
 
 +
// result > 0
 +
</rbcode>

Revision as of 18:46, 31 July 2019

Method

String.Compare(other As String, Optional options As Integer = 0, Optional locale As Locale = Nil) As Integer

Supported for all project types and targets.

Compares a text value with another text value. A non-empty text is always greater than an empty text. By default, a case-insensitive comparison is done. Returns a negative integer if the value is less than other, 0 if the two values are equal, and a positive integer if the value is greater than other.

Parameters

Parameter Description
other The String to compare with the original String.
options (Optional) Comparison options. Use constant CompareCaseSensitive for case-sensitive comparisons.
locale (Optional) The locale to use for comparisons. By default an invariant locale (not dependent on the system settings) is used.

Notes

By default this performs a case-insensitive comparison. To do a case-sensitive comparison, supply the CompareCaseSensitive constant to the options parameter.

By default comparisons are done in an invariant locale (i.e. not dependent on the user's preferences). The locale parameter can be used to specify an explicit locale to do comparisons in.

Exceptions

Sample Code

Compare two String values:

Var dog As String = "Dog"
Var cat As String = "Cat"

Var result As Integer
result = dog.Compare(cat)

// result > 0