org.as2lib.core.BasicClass +--org.as2lib.util.StringUtil
StringUtil offers a lot of different methods to work with strings.
static public function replace(string:String, what:String, to:String):String
Replaces all occurencies of the passed-in string what with the passed-in
string to in the passed-in string string.
string | the string to replace the content of |
what | the string to search and replace in the passed-in string
|
to | the string to insert instead of the passed-in string what
|
the result in which all occurences of the what string are replaced
by the to string
static public function trim(string:String):String
Removes all empty characters at the beginning and at the end of the passed-in
string.
Characters that are removed: spaces " ", line forwards "\n"
and extended line forwarding "\t\n".
string | the string to trim |
the trimmed string
static public function leftTrim(string:String):StringRemoves all empty characters at the beginning of a string.
Characters that are removed: spaces " ", line forwards "\n"
and extended line forwarding "\t\n".
string | the string to trim |
the trimmed string
static public function rightTrim(string:String):StringRemoves all empty characters at the end of a string.
Characters that are removed: spaces " ", line forwards "\n"
and extended line forwarding "\t\n".
string | the string to trim |
the trimmed string
static public function leftTrimForChars(string:String, chars:String):String
Removes all characters at the beginning of the string that match to the
set of chars.
This method splits all chars and removes occurencies at the beginning.
Example:
trace(StringUtil.rightTrimForChars("ymoynkeym", "ym")); // oynkeym
trace(StringUtil.rightTrimForChars("monkey", "mo")); // nkey
trace(StringUtil.rightTrimForChars("monkey", "om")); // nkey
string | the string to trim |
chars | the characters to remove from the beginning of the string
|
the trimmed string
static public function rightTrimForChars(string:String, chars:String):String
Removes all characters at the end of the string that match to the set of
chars.
This method splits all chars and removes occurencies at the end.
Example:
trace(StringUtil.rightTrimForChars("ymoynkeym", "ym")); // ymoynke
trace(StringUtil.rightTrimForChars("monkey***", "*y")); // monke
trace(StringUtil.rightTrimForChars("monke*y**", "*y")); // monke
string | the string to trim |
chars | the characters to remove from the end of the string
|
the trimmed string
static public function leftTrimForChar(string:String, char:String):String
Removes all characters at the beginning of the string that matches the
char.
Example:
trace(StringUtil.leftTrimForChar("yyyymonkeyyyy", "y"); // monkeyyyy
string | the string to trim |
char | the character to remove |
the trimmed string
| IllegalArgumentException | if you try to remove more than one character |
static public function rightTrimForChar(string:String, char:String):String
Removes all characters at the end of the string that matches the passed-in
char.
Example:
trace(StringUtil.rightTrimForChar("yyyymonkeyyyy", "y"); // yyyymonke
string | the string to trim |
char | the character to remove |
the trimmed string
| IllegalArgumentException | if you try to remove more than one character |
static public function checkEmail(email:String):Boolean
Validates the passed-in email adress to a predefined email pattern.
email | the email to check whether it is well-formatted |
true if the email matches the email pattern else false
static public function assureLength(string:String, length:Number):Boolean
Assures that the passed-in string is bigger or equal to the passed-in
length.
string | the string to validate |
length | the length the string should have
|
true if the length of string is bigger or equal to the
expected length else false
| IllegalArgumentException | if the expected length is less than 0 |
static public function contains(string:String, chars:String):Boolean
Evaluates if the passed-in chars are contained in the passed-in
string.
This methods splits the chars and checks if any character is contained
in the string.
Example:
trace(StringUtil.contains("monkey", "kzj0")); // true
trace(StringUtil.contains("monkey", "yek")); // true
trace(StringUtil.contains("monkey", "a")); // false
string | the string to check whether it contains any of the characters |
chars | the characters to look whether any of them is contained in the
string
|
true if one of the chars is contained in the string
static public function startsWith(string:String, searchString:String):Boolean
Evaluates if the passed-in stirng starts with the searchString.
string | the string to check |
searchString | the search string that may be at the beginning of string
|
true if string starts with searchString else
false.
static public function endsWith(string:String, searchString:String):Boolean
Tests whether the string ends with searchString.
string | the string to check |
searchString | the string that may be at the end of string
|
true if string ends with searchString
static public function addSpaceIndent(string:String, size:Number):String
Adds a space indent to the passed-in string.
This method is useful for different kind of ASCII output writing. It generates a dynamic size of space indents in front of every line inside a string. ################################################################################
Example:
var bigText = "My name is pretty important\n"
+ "because i am a interesting\n"
+ "small example for this\n"
+ "documentation.";
var result = StringUtil.addSpaceIndent(bigText, 3);
Contents of result:
My name is pretty important
because i am a interesting
small example for this
documentation.
indent will be floored.
string | the string that contains lines to indent |
the indented string
| IllegalArgumentException | if the size is smaller than 0
|
static public function multiply(string:String, factor:Number):String
Multiplies the passed-in string by the passed-in factor to create
long string blocks.
Example:
trace("Result: "+StringUtil.multiply(">", 6); // Result: >>>>>>
string | the source string to multiply |
factor | the number of times to multiply the string
|
static public function ucFirst(string:String):String
Capitalizes the first character of the passed-in string.
string | the string of which the first character shall be capitalized |
the passed-in string with the first character capitalized
static public function ucWords(string:String):String
Capitalizes the first character of every word in the passed-in string.
string | the string of which the first character of every word shall be capitalized |
the string with the first character of every word capitalized