Packagesystem.comparators
Classpublic class StringComparator
InheritanceStringComparator Inheritance Object
Implements Comparator

This comparator compare String objects.

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

system.Strings.compare


Public Properties
 PropertyDefined By
  ignoreCase : Boolean
Allow to take into account the case for comparison.
StringComparator
Public Methods
 MethodDefined 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
Public Constants
 ConstantDefined 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
Property Detail
ignoreCaseproperty
public var ignoreCase:Boolean

Allow to take into account the case for comparison.

Constructor Detail
StringComparator()Constructor
public function StringComparator(ignoreCase:Boolean = false)

Creates a new StringComparator instance.

Parameters
ignoreCase:Boolean (default = false) — a boolean to define if the comparator ignore case or not.
Method Detail
compare()method
public function compare(o1:*, o2:*, options:* = null):int

Returns 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.

Returns
int

  • -1 if o1 is "lower" than (less than, before, etc.) o2 ;
  • 1 if o1 is "higher" than (greater than, after, etc.) o2 ;
  • 0 if o1 and o2 are equal.
  • Constant Detail
    comparatorConstant
    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.

    ignoreCaseComparatorConstant 
    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.