| Package | system.comparators |
| Class | public class StringComparator |
| Inheritance | StringComparator Object |
| Implements | Comparator |
Example :
import system.comparators.StringComparator ;
var comp1:StringComparator = new StringComparator() ;
var comp2:StringComparator = new StringComparator(true) ; // ignore case
var s0:String = "HELLO" ;
var s1:String = "hello" ;
var s2:String = "welcome" ;
var s3:String = "world" ;
trace( comp1.compare(s1, s2) ) ; // -1
trace( comp1.compare(s2, s1) ) ; // 1
trace( comp1.compare(s1, s3) ) ; // 1
trace( comp1.compare(s1, s1) ) ; // 0
trace( comp1.compare(s1, s0) ) ; // 0
trace( comp2.compare(s1, s0) ) ; // -1
See also
| Property | Defined By | ||
|---|---|---|---|
| ignoreCase : Boolean
Allow to take into account the case for comparison. | StringComparator | ||
| Method | Defined By | ||
|---|---|---|---|
StringComparator(ignoreCase:Boolean = false)
Creates a new StringComparator instance. | StringComparator | ||
compare(o1:*, o2:*, options:* = null):int
Returns an integer value to compare two String objects. | StringComparator | ||
| Constant | Defined By | ||
|---|---|---|---|
| comparator : StringComparator [static]
The static StringComparator singleton with the a false ignoreCase default property. | StringComparator | ||
| ignoreCaseComparator : StringComparator [static]
The static StringComparator singleton with the a true ignoreCase property. | StringComparator | ||
| ignoreCase | property |
public var ignoreCase:BooleanAllow to take into account the case for comparison.
| StringComparator | () | Constructor |
public function StringComparator(ignoreCase:Boolean = false)Creates a new StringComparator instance.
ParametersignoreCase:Boolean (default = false) — a boolean to define if the comparator ignore case or not.
|
| compare | () | method |
public function compare(o1:*, o2:*, options:* = null):intReturns an integer value to compare two String objects.
Parameters
o1:* — the first String object to compare.
| |
o2:* — the second String object to compare.
| |
options:* (default = null) — A boolean who indicates if the Comparator ignore the case or not. If this parameter is null the internal ignoreCase property is used.
|
int —
|
| comparator | Constant |
public static const comparator:StringComparator
The static StringComparator singleton with the a false ignoreCase default property.
Clients are encouraged to use the value returned from this constant instead of constructing a new instance to reduce allocation and garbage collection overhead when multiple StringComparators may be used in the same application.
| ignoreCaseComparator | Constant |
public static const ignoreCaseComparator:StringComparator
The static StringComparator singleton with the a true ignoreCase property.
Clients are encouraged to use the value returned from this contant instead of constructing a new instance to reduce allocation and garbage collection overhead when multiple StringComparators may be used in the same application.