| Package | system |
| Class | public class Strings |
| Inheritance | Strings Object |
| Property | Defined By | ||
|---|---|---|---|
| evaluators : Object [static]
Contain a list of evaluators to be used in Strings.format
ex:
Strings.evaluators = { math: new MathEvaluator() };
Strings.format( "my result is ${2+3}math$" ); // "my result is 5"
note:
property names in the evaluators object can only contains
lower case alphabetical chars and digit chars
| Strings | ||
| Method | Defined By | ||
|---|---|---|---|
compare(o1:String, o2:String, strict:Boolean = false):int [static]
Compares the two specified String objects. | Strings | ||
endsWith(str:String, value:String):Boolean [static]
Determines whether the end of this instance matches the specified String. | Strings | ||
format(format:String, ... args):String [static]
Format a string using indexed, named and/or evaluated parameters. | Strings | ||
splitToChars(str:String, modifier:String = toString):Array [static]
Split every individual char in a string to an array of Char instances. | Strings | ||
startsWith(str:String, value:String):Boolean [static]
Determines whether a specified string is a prefix of the current instance. | Strings | ||
| evaluators | property |
public static var evaluators:ObjectContain a list of evaluators to be used in Strings.format ex: Strings.evaluators = { math: new MathEvaluator() }; Strings.format( "my result is ${2+3}math$" ); // "my result is 5" note: property names in the evaluators object can only contains lower case alphabetical chars and digit chars
| compare | () | method |
public static function compare(o1:String, o2:String, strict:Boolean = false):intCompares the two specified String objects. Allows to take into account the string case for comparison.
Parameters
o1:String — first string to compare with the second string.
| |
o2:String — second string to compare with the first string.
| |
strict:Boolean (default = false) — (optionnal) useCase boolean, default to false.
|
int |
| endsWith | () | method |
public static function endsWith(str:String, value:String):BooleanDetermines whether the end of this instance matches the specified String.
Example :
import system.Strings ;
var result:;
result = Strings.endsWith( "hello world", "world" );
trace("> " + result) ; // true
result = Strings.endsWith( "hello world", "hello" );
trace("> " + result) ; // false
Parameters
str:String | |
value:String |
Boolean |
| format | () | method |
public static function format(format:String, ... args):StringFormat a string using indexed, named and/or evaluated parameters.
Method call :
Replaces the pattern item in a specified String with the text equivalent of the value of a specified Object instance.
Formats item : {token[,alignment][:paddingChar]}
If you want to escape the "{" and "}" chars use "{{" and "}}"
Example :
import system.Strings ;
var result:String ;
// indexed from the arguments
result = Strings.format( "hello {1} {0} world", "big", "the" );
trace( result ) ; //"hello the big world"
result = Strings.format("Brad's dog has {0,6:#} fleas.", 41) ;
trace( result ) ;
result = Strings.format("Brad's dog has {0,-6} fleas.", 12) ;
trace( result) ;
result = Strings.format("{3} {2} {1} {0}", "a", "b", "c", "d") ;
trace( result ) ;
// named from an object
result = Strings.format( "hello I'm {name}", {name:"HAL"} );
trace( result ) ; //"hello I'm HAL"
// indexed from an array
var names:Array = ["A","B","C","D"];
var scores:Array = [16,32,128,1024];
for( var i:int=0; i<names.length; i++ )
{
trace( Strings.format( "{0} scored {1,5}", [names[i], scores[i]] ) );
}
// "A scored 16"
// "B scored 32"
// "C scored 128"
// "D scored 1024"
// resolve toString
var x:Object = {};
x.toString = function() { return "john doe"; } ;
trace( Strings.format( "Who is {0} ?", x ) ) ; //"Who is john doe ?"
// you can off course reuse the index
var fruits:Array = ["apple", "banana", "pineapple"] ;
trace( Strings.format( "I like all fruits {0},{1},{2}, etc. but still I prefer above all {0}", fruits ) ); // "I like all fruits apple,banana,pineapple, etc. but still I prefer above all apple"
// indexed from an array + the arguments
var fruits:Array = ["apple", "banana", "pineapple"];
trace( Strings.format( "fruits: {0}, {1}, {2}, {3}, {4}, {5}", fruits, "grape", "tomato" ) ); //"fruits: apple, banana, pineapple, grape, tomato, undefined"
// passing reference and padding
var what = "answer" ;
result = Strings.format( "your {0} is within {answer,20:.}", {answer:"my answer"}, what ) ;
trace( result ) // "your answer is within ...........my answer"
// using evaluated parameters
Strings.evaluators = { math: new MathEvaluator() };
Strings.format( "my result is ${2+3}math$" ); // "my result is 5"
//by default evaluated parameters use EdenEvaluator with serialized result
Strings.format( "here some object '${ {a:1,b:2} }$'" ); //"here some object '{a:1,b:2}'"
//use EdenEvaluator with stringified result
Strings.evaluators = { math: new EdenEvaluator(false) };
Strings.format( "here some object '${ {a:1,b:2} }eden$'" ); //"here some object '[object Object]'"
Strings.format( "the host is ${system.Environment.host}eden$" ); //"the host is Flash 9.0.115.0"
//use chained evaluators
Strings.evaluators = { eden: new EdenEvaluator(false), date: new DateEvaluator() ];
Strings.format( "my date is ${new Date(2007,4,22,13,13,13)}eden,date$" ); //"my date is 22.05.2007 13:13:13"
Parameters
format:String | |
... args |
String |
| splitToChars | () | method |
public static function splitToChars(str:String, modifier:String = toString):ArraySplit every individual char in a string to an array of Char instances.
Parameters
str:String — The string to split
| |
modifier:String (default = toString) — The optional string modifier name (a function to apply)
|
Array |
| startsWith | () | method |
public static function startsWith(str:String, value:String):BooleanDetermines whether a specified string is a prefix of the current instance.
Example :
import system.Strings ;
trace( Strings.startsWith("hello world", "h") ) ; // true
trace( Strings.startsWith("hello world", "hello") ) ; // true
trace( Strings.startsWith("hello world", "a") ) ; // false
Parameters
str:String | |
value:String |
Boolean — true if the specified string is a prefix of the current instance.
|