Package | org.as3utils |
Class | public final class StringUtil |
Inheritance | StringUtil Object |
String
objects.
StringUtil handles null
input Strings quietly. That is to say that a null
input will return null
.
Where a Boolean
or int
is being returned details vary by method.
Some terms used by this class related to String
handling:
String
("")String
object only with control chars (space, \t, \n, \s)Method | Defined By | ||
---|---|---|---|
StringUtil is a static class and shouldn't be instantiated. | StringUtil | ||
abbreviate(str:String, maxWidth:int):String [static]
Abbreviates a String object using ellipses. | StringUtil | ||
capitalize(str:String):String [static]
Capitalizes a String object, changing only the first letter to uppercase. | StringUtil | ||
contains(str:String, search:String, stringCase:StringCase):Boolean [static]
Checks if the String object contains the specified search String object. | StringUtil | ||
containsAny(str:String, search:String, stringCase:StringCase):Boolean [static]
Checks if the String object contains any character in the given set of characters. | StringUtil | ||
containsNone(str:String, invalidChars:String, stringCase:StringCase):Boolean [static]
Checks if the String object does not contain any of the characters of the given set of characters. | StringUtil | ||
containsOnly(str:String, validChars:String, stringCase:StringCase):Boolean [static]
Checks if the String object contains only characters in the given set of characters. | StringUtil | ||
countMatches(str:String, sub:String, stringCase:StringCase):int [static]
Counts how many times the substring appears in the String object. | StringUtil | ||
defaultIfEmpty(str:String, defaultStr:String):String [static]
Returns either the passed in String object, or if the String object is empty ("") or null, the value of defaultStr. | StringUtil | ||
endsWith(str:String, suffix:String, stringCase:StringCase):Boolean [static]
Check if the String object ends with a specified suffix. | StringUtil | ||
equals(str1:String, str2:String, stringCase:StringCase):Boolean [static]
Compares two String objects, returning true if they are equal. | StringUtil | ||
firstChar(str:String):String [static]
Returns the first char of the String object. | StringUtil | ||
isAllLowerCase(str:String):Boolean [static]
Checks if the String object contains only lowercase characters. | StringUtil | ||
isAllUpperCase(str:String):Boolean [static]
Checks if the String object contains only uppercase characters. | StringUtil | ||
isAlphanumeric(str:String):Boolean [static]
Checks if the String object contains only unicode letters or digits. | StringUtil | ||
isAlphanumericSpace(str:String):Boolean [static]
Checks if the String object contains only unicode letters, digits or spaces. | StringUtil | ||
isBlank(str:String):Boolean [static]
Checks if a String object is empty (""), null or if it contains only control characters(char <= 32). | StringUtil | ||
isEmpty(str:String):Boolean [static]
Checks if a String object is empty ("") or null. | StringUtil | ||
isNotBlank(str:String):Boolean [static]
Checks if a String object is not empty (""), not null and not contains only control characters(char <= 32). | StringUtil | ||
isNotEmpty(str:String):Boolean [static]
Checks if a String object is not empty ("") and not null. | StringUtil | ||
isNumeric(str:String):Boolean [static]
Checks if the String object contains only unicode digits. | StringUtil | ||
isNumericSpace(str:String):Boolean [static]
Checks if the String object contains only unicode digits or spaces. | StringUtil | ||
isValidEmail(str:String):Boolean [static]
Validates an input e-mail address. | StringUtil | ||
lastChar(str:String):String [static]
Returns the last char of the String object. | StringUtil | ||
ltrim(str:String):String [static]
Removes control characters(char <= 32) from the start of the String object. | StringUtil | ||
remove(str:String, remove:String, stringCase:StringCase):String [static]
Removes all occurrences of a substring from within the source String object. | StringUtil | ||
removeAccentuation(str:String):String [static]
Remove accented characters from the String object. | StringUtil | ||
removeEnd(str:String, remove:String, stringCase:StringCase):String [static]
Removes a substring only if it is at the end of the source String object, otherwise returns the source String object. | StringUtil | ||
removeFirstCharacter(str:String):String [static]
Removes the first character of the String object. | StringUtil | ||
removeLastCharacter(str:String):String [static]
Removes the last character of the String object. | StringUtil | ||
removeStart(str:String, remove:String, stringCase:StringCase):String [static]
Removes a substring only if it is at the start of the source String object, otherwise returns the source String object. | StringUtil | ||
replaceExtended(str:String, find:String, replaceBy:String, stringCase:StringCase):String [static]
Search for all occurrences of the String find within the String str and replaces by the String replaceBy. | StringUtil | ||
reverse(str:String):String [static]
Reverses the chars of the String object. | StringUtil | ||
rtrim(str:String):String [static]
Removes control characters(char <= 32) from the start of the String object. | StringUtil | ||
startsWith(str:String, prefix:String, stringCase:StringCase):Boolean [static]
Check if the String object starts with a specified prefix. | StringUtil | ||
trim(str:String):String [static]
Removes control characters(char <= 32) from the start and end of the String object. | StringUtil | ||
trimToEmpty(str:String):String [static]
Removes control characters(char <= 32) from the start and end of the String object. | StringUtil | ||
trimToNull(str:String):String [static]
Removes control characters(char <= 32) from the start and end of the String object. | StringUtil | ||
uncapitalize(str:String):String [static]
Uncapitalizes a String object, changing only the first letter to lowercase. | StringUtil |
StringUtil | () | Constructor |
public function StringUtil()
StringUtil is a static class and shouldn't be instantiated.
IllegalOperationError — StringUtil is a static class and shouldn't be instantiated.
|
abbreviate | () | method |
public static function abbreviate(str:String, maxWidth:int):String
Abbreviates a String
object using ellipses.
Parameters
str:String — the String object to check. May be null .
| |
maxWidth:int — maximum length of the result String object, must be at least 4.
|
String — the abbreviated String object. If the str argument is null then the return is null .
|
ArgumentError — If the maxWidth argument is less than 4.
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.abbreviate(null , 4) // null StringUtil.abbreviate("" , 4) // StringUtil.abbreviate(" " , 4) // StringUtil.abbreviate("a" , 4) // a StringUtil.abbreviate("ab" , 4) // ab StringUtil.abbreviate("abcdefghij" , 4) // a... StringUtil.abbreviate("abcdefghij" , 5) // ab... StringUtil.abbreviate(" abcdefghij" , 5) // a... StringUtil.abbreviate("a bcdefghij" , 5) // a... StringUtil.abbreviate(" a bcdefghij", 5) // a... StringUtil.abbreviate("abcdefghij" , 6) // abc... StringUtil.abbreviate(" abcdefghij" , 6) // ab... StringUtil.abbreviate("a bcdefghij" , 6) // a b... StringUtil.abbreviate(" a bcdefghij", 6) // a... StringUtil.abbreviate("abcdefghij" , 7) // abcd... StringUtil.abbreviate("abcdefghij" , 8) // abcde... StringUtil.abbreviate("abcdefghij" , 9) // abcdef... StringUtil.abbreviate("abcdefghij" , 10) // abcdefghij StringUtil.abbreviate("abcdefghij" , 11) // abcdefghij StringUtil.abbreviate("abcdefghij" , 12) // abcdefghij
capitalize | () | method |
public static function capitalize(str:String):String
Capitalizes a String
object, changing only the first letter to uppercase.
Parameters
str:String — the String object to capitalize. May be null .
|
String — the capitalized String . If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.capitalize(null) // null StringUtil.capitalize(" ") // StringUtil.capitalize("a") // A StringUtil.capitalize("A") // A StringUtil.capitalize("ab") // Ab StringUtil.capitalize("Ab") // Ab StringUtil.capitalize("aB") // AB StringUtil.capitalize("AB") // AB StringUtil.capitalize("abc") // Abc StringUtil.capitalize(" abc") // abc StringUtil.capitalize(" Abc") // Abc
contains | () | method |
public static function contains(str:String, search:String, stringCase:StringCase):Boolean
Checks if the String
object contains the specified search String
object.
Parameters
str:String — the String object to check. May be null .
| |
search:String — the String object to find. May be null .
| |
stringCase:StringCase — indicates whether case sensitivity is considered or not in the comparison.
|
Boolean — true if the String object contains the search String object, false if not. If the str or search argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.contains(null , null) // false StringUtil.contains(null , "") // false StringUtil.contains("" , null) // false StringUtil.contains(" " , " ") // true StringUtil.contains(" " , "") // true StringUtil.contains("" , " ") // false StringUtil.contains("abc", "") // true StringUtil.contains("" , "abc") // false StringUtil.contains("abc", "a") // true StringUtil.contains("abc", "A") // false StringUtil.contains("abc", "A", false) // true StringUtil.contains("Abc", "a") // false StringUtil.contains("Abc", "a", false) // true StringUtil.contains("abc", "á") // false StringUtil.contains("ábc", "a") // false StringUtil.contains("ábc", "á") // true StringUtil.contains("a" , "abc") // false
containsAny | () | method |
public static function containsAny(str:String, search:String, stringCase:StringCase):Boolean
Checks if the String
object contains any character in the given set of characters.
Parameters
str:String — the String object to check. May be null .
| |
search:String — the chars to find. May be null .
| |
stringCase:StringCase — indicates whether case sensitivity is considered or not in the comparison.
|
Boolean — true if the String object contains any of the chars of the search String object, false if not. If the str or search argument is null then the return is false .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.containsAny(null , null) // false StringUtil.containsAny("abc", "") // false StringUtil.containsAny("abc", "a") // true StringUtil.containsAny("b" , "abc") // true StringUtil.containsAny("A" , "abc") // false StringUtil.containsAny("A" , "abc", false) // true StringUtil.containsAny("a" , "ABC") // false StringUtil.containsAny("a" , "ABC", false) // true
containsNone | () | method |
public static function containsNone(str:String, invalidChars:String, stringCase:StringCase):Boolean
Checks if the String
object does not contain any of the characters of the given set of characters.
Parameters
str:String — the String object to check. May be null .
| |
invalidChars:String — the invalid chars. May be null .
| |
stringCase:StringCase — indicates whether case sensitivity is considered or not in the comparison.
|
Boolean — true if the String object does not contains any of the chars of the invalidChars String object, false if does. If the str or invalidChars argument is null then the return is true .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.containsNone(null , null) // true StringUtil.containsNone("abc" , "") // true StringUtil.containsNone("abc", "a") // false StringUtil.containsNone("b" , "abc") // false StringUtil.containsNone("A" , "abc") // true StringUtil.containsNone("A" , "abc", false) // false StringUtil.containsNone("a" , "ABC") // true StringUtil.containsNone("a" , "ABC", false) // false
containsOnly | () | method |
public static function containsOnly(str:String, validChars:String, stringCase:StringCase):Boolean
Checks if the String
object contains only characters in the given set of characters.
Parameters
str:String — the String object to check. May be null .
| |
validChars:String — the valid chars. May be null .
| |
stringCase:StringCase — indicates whether case sensitivity is considered or not in the comparison.
|
Boolean — true if the String object contains only characters that exist in the validChars argument, false if contains any other characters. If the str or validChars argument is null then the return is false .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.containsOnly(null , null) // false StringUtil.containsOnly("abc", "") // false StringUtil.containsOnly("abc", "a") // false StringUtil.containsOnly("abc", "b") // false StringUtil.containsOnly("b" , "abc") // true StringUtil.containsOnly("ba" , "abc") // true StringUtil.containsOnly("A" , "abc") // false StringUtil.containsOnly("A" , "abc", false) // true StringUtil.containsOnly("a" , "ABC") // false StringUtil.containsOnly("a" , "ABC", false) // true
countMatches | () | method |
public static function countMatches(str:String, sub:String, stringCase:StringCase):int
Counts how many times the substring appears in the String
object.
Parameters
str:String — the String object to check. May be null .
| |
sub:String — the substring to count. May be null .
| |
stringCase:StringCase — indicates whether case sensitivity is considered or not in the comparison.
|
int — the number of occurrences or 0 if either argument is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.countMatches(null , null) // 0 StringUtil.countMatches("abc" , "") // 0 StringUtil.countMatches("abc" , "a") // 1 StringUtil.countMatches("abc" , "á") // 0 StringUtil.countMatches("ábca" , "á") // 1 StringUtil.countMatches("abc" , "b") // 1 StringUtil.countMatches("a" , "abc") // 0 StringUtil.countMatches("abc" , "aa") // 0 StringUtil.countMatches("abca" , "a") // 2 StringUtil.countMatches("abca" , "aa") // 0 StringUtil.countMatches("aabca", "aa") // 1 StringUtil.countMatches("abc" , "ba") // 0 StringUtil.countMatches("abc" , "A") // 0 StringUtil.countMatches("abc" , "A", false) // 1 StringUtil.countMatches("abca" , "A", false) // 2
defaultIfEmpty | () | method |
public static function defaultIfEmpty(str:String, defaultStr:String):String
Returns either the passed in String
object, or if the String
object is empty ("") or null
, the value of defaultStr.
Parameters
str:String — the String object to check. May be null .
| |
defaultStr:String — the default String object to return if the str argument is empty ("") or null . May be null .
|
String — the defaultStr argument if the str argument is empty ("") or null , or the str argument otherwise.
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.defaultIfEmpty(null , null) // null StringUtil.defaultIfEmpty("" , null) // null StringUtil.defaultIfEmpty(null , "abc") // abc StringUtil.defaultIfEmpty("abc" , "") // abc StringUtil.defaultIfEmpty("abc" , null) // abc StringUtil.defaultIfEmpty(" " , "abc") // abc StringUtil.defaultIfEmpty(" \n\t ", "abc") // abc
endsWith | () | method |
public static function endsWith(str:String, suffix:String, stringCase:StringCase):Boolean
Check if the String
object ends with a specified suffix.
Parameters
str:String — the String object to check. May be null .
| |
suffix:String — the suffix to find. May be null .
| |
stringCase:StringCase — indicates whether case sensitivity is considered or not in the comparison.
|
Boolean — true if the String object ends with the suffix or if both arguments are null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.endsWith(null , null) // true StringUtil.endsWith("" , null) // false StringUtil.endsWith(null , "abc") // false StringUtil.endsWith("abcdef", "f") // true StringUtil.endsWith("abcdef", "F") // false StringUtil.endsWith("abcdef", "F", false) // true StringUtil.endsWith("abcdEF", "eF") // false StringUtil.endsWith("abcdEF", "eF", false) // true StringUtil.endsWith("abcdef", "ef") // true StringUtil.endsWith("abcdef", "abcdef") // true StringUtil.endsWith("abcdef", "abcdefg") // false
equals | () | method |
public static function equals(str1:String, str2:String, stringCase:StringCase):Boolean
Compares two String
objects, returning true
if they are equal.
Two null
references are considered to be equal.
Parameters
str1:String — the first String object. May be null .
| |
str2:String — the second String object. May be null .
| |
stringCase:StringCase — indicates whether case sensitivity is considered or not in the comparison.
|
Boolean — true if the String objects are equal or both are null .
|
import org.as3coreaddendum.utils.StringUtil; var obj:Object = {label:"jlm"}; var n1:int = 1; var n2:Number = 2; var n3:Number = 3.1; var arr:Array = ["abc", "def", 123, {label:"ghi"}, obj, n1, n2, n3]; StringUtil.equals(null , null) // true StringUtil.equals("" , null) // false StringUtil.equals(null , "abc") // false StringUtil.equals("abc", "a") // false StringUtil.equals("abc", "abc") // true StringUtil.equals("abc", "AbC") // false StringUtil.equals("abc", "AbC", false) // true
firstChar | () | method |
public static function firstChar(str:String):String
Returns the first char of the String
object.
Parameters
str:String — the String object to return the first char. May be null .
|
String — the first char of the String object. If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.firstChar(null) // null StringUtil.firstChar("") // StringUtil.firstChar(" ") // StringUtil.firstChar("a") // a StringUtil.firstChar("ab") // a StringUtil.firstChar("abc") // a StringUtil.firstChar(" abc") // StringUtil.firstChar(" abc ") //
isAllLowerCase | () | method |
public static function isAllLowerCase(str:String):Boolean
Checks if the String
object contains only lowercase characters.
Parameters
str:String — the String object to check. May be null .
|
Boolean — true if only contains lowercase characters, and is not null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.isAllLowerCase(null) // false StringUtil.isAllLowerCase("") // false StringUtil.isAllLowerCase(" ") // false StringUtil.isAllLowerCase(" \t ") // false StringUtil.isAllLowerCase("abc") // true StringUtil.isAllLowerCase("Abc") // false StringUtil.isAllLowerCase("ABC") // false StringUtil.isAllLowerCase("óbc") // true StringUtil.isAllLowerCase("Óbc") // false StringUtil.isAllLowerCase("ÓBC") // false
isAllUpperCase | () | method |
public static function isAllUpperCase(str:String):Boolean
Checks if the String
object contains only uppercase characters.
Parameters
str:String — the String object to check. May be null .
|
Boolean — true if only contains uppercase characters, and is not null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.isAllUpperCase(null) // false StringUtil.isAllUpperCase("") // false StringUtil.isAllUpperCase(" ") // false StringUtil.isAllUpperCase(" ") // false StringUtil.isAllUpperCase("abc") // false StringUtil.isAllUpperCase("Abc") // false StringUtil.isAllUpperCase("ABC") // true StringUtil.isAllUpperCase("óbc") // false StringUtil.isAllUpperCase("Óbc") // false StringUtil.isAllUpperCase("ÓBC") // true
isAlphanumeric | () | method |
public static function isAlphanumeric(str:String):Boolean
Checks if the String
object contains only unicode letters or digits.
Parameters
str:String — the String object to check. May be null .
|
Boolean — true if only contains unicode letters or digits, and is not null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.isAlphanumeric(null) // false StringUtil.isAlphanumeric("") // false StringUtil.isAlphanumeric(" ") // false StringUtil.isAlphanumeric(" \t ") // false StringUtil.isAlphanumeric("abc") // true StringUtil.isAlphanumeric("123456") // true StringUtil.isAlphanumeric("abc123") // true StringUtil.isAlphanumeric("123abc456def") // true StringUtil.isAlphanumeric("abc123 ") // false StringUtil.isAlphanumeric("ABC123 ") // false StringUtil.isAlphanumeric("áóbc123") // true StringUtil.isAlphanumeric("ÁÓbc123") // true StringUtil.isAlphanumeric("ÁÓbc123-") // false
isAlphanumericSpace | () | method |
public static function isAlphanumericSpace(str:String):Boolean
Checks if the String
object contains only unicode letters, digits or spaces.
Parameters
str:String — the String object to check. May be null .
|
Boolean — true if only contains unicode letters, digits and spaces and is not null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.isAlphanumericSpace(null) // false StringUtil.isAlphanumericSpace("") // false StringUtil.isAlphanumericSpace(" ") // true StringUtil.isAlphanumericSpace(" \t ") // false StringUtil.isAlphanumericSpace("abc") // true StringUtil.isAlphanumericSpace("123456") // true StringUtil.isAlphanumericSpace("abc123") // true StringUtil.isAlphanumericSpace("123abc456def") // true StringUtil.isAlphanumericSpace("abc123 ") // true StringUtil.isAlphanumericSpace("ABC123 ") // true StringUtil.isAlphanumericSpace("áóbc123") // true StringUtil.isAlphanumericSpace("ÁÓbc123") // true StringUtil.isAlphanumericSpace("ÁÓbc123-") // false
isBlank | () | method |
public static function isBlank(str:String):Boolean
Checks if a String
object is empty (""), null
or if it contains only control characters(char <= 32).
Parameters
str:String — the String object to check. May be null .
|
Boolean — true if the String object is null , empty or contains only control characters(char <= 32).
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.isBlank(null) // true StringUtil.isBlank("") // true StringUtil.isBlank(" ") // true StringUtil.isBlank(" \t ") // true StringUtil.isBlank("abc") // false StringUtil.isBlank(" abc ") // false
isEmpty | () | method |
public static function isEmpty(str:String):Boolean
Checks if a String
object is empty ("") or null
.
Parameters
str:String — the String object to check. May be null .
|
Boolean — true if the String object is empty or null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.isEmpty(null) // true StringUtil.isEmpty("") // true StringUtil.isEmpty(" ") // false StringUtil.isEmpty(" \t ") // false StringUtil.isEmpty("abc") // false StringUtil.isEmpty(" abc ") // false
isNotBlank | () | method |
public static function isNotBlank(str:String):Boolean
Checks if a String
object is not empty (""), not null
and not contains only control characters(char <= 32).
Parameters
str:String — the String object to check. May be null .
|
Boolean — true if the String object is not empty, not null and not contains only control characters(char <= 32).
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.isNotBlank(null) // false StringUtil.isNotBlank("") // false StringUtil.isNotBlank(" ") // false StringUtil.isNotBlank(" \t ") // false StringUtil.isNotBlank("abc") // true StringUtil.isNotBlank(" abc ") // true
isNotEmpty | () | method |
public static function isNotEmpty(str:String):Boolean
Checks if a String
object is not empty ("") and not null
.
Parameters
str:String — the String object to check. May be null .
|
Boolean — true if the String object is not empty and is not null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.isNotEmpty(null) // false StringUtil.isNotEmpty("") // false StringUtil.isNotEmpty(" ") // true StringUtil.isNotEmpty(" \t ") // true StringUtil.isNotEmpty("abc") // true StringUtil.isNotEmpty(" abc ") // true
isNumeric | () | method |
public static function isNumeric(str:String):Boolean
Checks if the String
object contains only unicode digits. A decimal point is not a unicode digit and returns false
.
Parameters
str:String — the String object to check. May be null .
|
Boolean — true if the String object only contains unicode digits and is not null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.isNumeric(null) // false StringUtil.isNumeric("") // true StringUtil.isNumeric(" ") // false StringUtil.isNumeric(" \t ") // false StringUtil.isNumeric("123") // true StringUtil.isNumeric("12.3") // false StringUtil.isNumeric("a123") // false StringUtil.isNumeric(" 123") // false StringUtil.isNumeric(" 123") // false
isNumericSpace | () | method |
public static function isNumericSpace(str:String):Boolean
Checks if the String
object contains only unicode digits or spaces. A decimal point is not a unicode digit and returns false
.
Parameters
str:String — the String object to check. May be null .
|
Boolean — true if the String object only contains unicode digits or spaces and is not null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.isNumericSpace(null) // false StringUtil.isNumericSpace("") // true StringUtil.isNumericSpace(" ") // true StringUtil.isNumericSpace(" \t ") // false StringUtil.isNumericSpace("123") // true StringUtil.isNumericSpace("12.3") // false StringUtil.isNumericSpace("a123") // false StringUtil.isNumericSpace(" 123") // true StringUtil.isNumericSpace(" 123") // true
isValidEmail | () | method |
public static function isValidEmail(str:String):Boolean
Validates an input e-mail address.
This implementation does not conform with any specification and is very restrictive.
Parameters
str:String — the String object to be validates as an e-mail address.
|
Boolean — true if the String object is a valid e-mail address according to this implementation.
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.isValidEmail(null) // false StringUtil.isValidEmail("") // false StringUtil.isValidEmail("a") // false StringUtil.isValidEmail("a@a.a") // false StringUtil.isValidEmail("aa@aa.aa") // true StringUtil.isValidEmail("a/a@aa.aa") // false StringUtil.isValidEmail("a=a@aa.aa") // false StringUtil.isValidEmail("1a@1a.1a") // false StringUtil.isValidEmail("a1@a1.a1") // false StringUtil.isValidEmail("a1@a1.aa") // true StringUtil.isValidEmail("11@11.11") // false StringUtil.isValidEmail("aa-aa@a-a.a-a") // false StringUtil.isValidEmail("aa-aa@aa-aa.aa-aa") // false StringUtil.isValidEmail("aa-aa@aa-aa-aa.aa") // true StringUtil.isValidEmail("aa-aa@aa.aa.aa") // true StringUtil.isValidEmail("áa-aa@aa.aa.aa") // false StringUtil.isValidEmail("Aa-aa@aa.aa.aA") // true StringUtil.isValidEmail("aa-aa@aa.aa.aa") // true
lastChar | () | method |
public static function lastChar(str:String):String
Returns the last char of the String
object.
Parameters
str:String — the String object to return the last char. May be null .
|
String — the last char of the String object. If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.lastChar(null) // null StringUtil.lastChar("") // StringUtil.lastChar(" ") // StringUtil.lastChar("a") // a StringUtil.lastChar("ab") // b StringUtil.lastChar("abc") // c StringUtil.lastChar(" abc") // c StringUtil.lastChar(" abc ") //
ltrim | () | method |
public static function ltrim(str:String):String
Removes control characters(char <= 32) from the start of the String
object.
Parameters
str:String — the String object to be trimmed. May be null .
|
String — the trimmed String object. If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.ltrim(null) // null StringUtil.ltrim("") // StringUtil.ltrim(" ") // StringUtil.ltrim(" ") // StringUtil.ltrim(" ") // StringUtil.ltrim("abc"): // abc StringUtil.ltrim(" abc") // abc StringUtil.ltrim(" abc") // abc StringUtil.ltrim(" abc ") // abc StringUtil.ltrim(" \t\n abc ") // abc StringUtil.ltrim(" \t\n abc \t\n ") // abc \t\n
remove | () | method |
public static function remove(str:String, remove:String, stringCase:StringCase):String
Removes all occurrences of a substring from within the source String
object.
Parameters
str:String — the String object to search. May be null .
| |
remove:String — the String object to search for and remove. May be null .
| |
stringCase:StringCase — indicates whether case sensitivity is considered or not in the comparison.
|
String — the String object with the substring removed if found. If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.remove(null , null) // null StringUtil.remove("" , null) // StringUtil.remove(null , "abc") // null StringUtil.remove("" , "") // StringUtil.remove("abc" , "") // abc StringUtil.remove("" , "abc") // StringUtil.remove("abcdef", "c") // abdef StringUtil.remove("abcdef", "C") // abcdef StringUtil.remove("abcdef", "C", false) // abdef StringUtil.remove("ABcdef", "aB") // ABcdef StringUtil.remove("ABcdef", "aB", false) // cdef StringUtil.remove("ABcdeF", "Ef") // ABcdeF StringUtil.remove("ABcdeF", "Ef", false) // ABcd StringUtil.remove("abcdef", "ab") // cdef StringUtil.remove("abcdef", "abcdef") // StringUtil.remove("abcdef", "abcdefg") // abcdef
removeAccentuation | () | method |
public static function removeAccentuation(str:String):String
Remove accented characters from the String
object.
Parameters
str:String — the String object to remove accented characters. May be null .
|
String — the String object without accented characters.
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.removeAccentuation(null) // null StringUtil.removeAccentuation("") // StringUtil.removeAccentuation(" ") // StringUtil.removeAccentuation("aáeéiíoóuúçÇÁbÜõ") // aaeeiioouucCAbUo
removeEnd | () | method |
public static function removeEnd(str:String, remove:String, stringCase:StringCase):String
Removes a substring only if it is at the end of the source String
object, otherwise returns the source String
object.
Parameters
str:String — the String object to search. May be null .
| |
remove:String — the String object to search for and remove. May be null .
| |
stringCase:StringCase — indicates whether case sensitivity is considered or not in the comparison.
|
String — the String object with the substring removed if found. If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.removeEnd(null , null) // null StringUtil.removeEnd("" , null) // StringUtil.removeEnd(null , "abc") // null StringUtil.removeEnd("" , "") // StringUtil.removeEnd("abc" , "") // abc StringUtil.removeEnd("" , "abc") // StringUtil.removeEnd("abcdef", "c") // abcdef StringUtil.removeEnd("abcdef", "C") // abcdef StringUtil.removeEnd("abcdef", "C", false) // abcdef StringUtil.removeEnd("ABcdef", "aB") // ABcdef StringUtil.removeEnd("ABcdef", "aB", false) // ABcdef StringUtil.removeEnd("ABcdeF", "Ef") // ABcdeF StringUtil.removeEnd("ABcdeF", "Ef", false) // ABcd StringUtil.removeEnd("abcdef", "ab") // abcdef StringUtil.removeEnd("abcdef", "abcdef") // StringUtil.removeEnd("abcdef", "abcdefg") // abcdef
removeFirstCharacter | () | method |
public static function removeFirstCharacter(str:String):String
Removes the first character of the String
object.
Parameters
str:String — the String object to remove the first character from. May be null .
|
String — the String object without first character. If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.removeFirstCharacter(null) // null StringUtil.removeFirstCharacter(""): // StringUtil.removeFirstCharacter("a"): // StringUtil.removeFirstCharacter("ab") // b StringUtil.removeFirstCharacter("abc") // bc StringUtil.removeFirstCharacter("abc\t\ndef") // bc\t\ndef
removeLastCharacter | () | method |
public static function removeLastCharacter(str:String):String
Removes the last character of the String
object.
Parameters
str:String — the String object to remove last character from. May be null .
|
String — the String object without last character. If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.removeLastCharacter(null) // null StringUtil.removeLastCharacter(""): // StringUtil.removeLastCharacter("a"): // StringUtil.removeLastCharacter("ab") // a StringUtil.removeLastCharacter("abc") // ab StringUtil.removeLastCharacter("abc\t\ndef") // abc\t\nde
removeStart | () | method |
public static function removeStart(str:String, remove:String, stringCase:StringCase):String
Removes a substring only if it is at the start of the source String
object, otherwise returns the source String
object.
Parameters
str:String — the String object to search. May be null .
| |
remove:String — the String object to search for and remove. May be null .
| |
stringCase:StringCase — indicates whether case sensitivity is considered or not in the comparison.
|
String — the String object with the substring removed if found. If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.removeStart(null , null) // null StringUtil.removeStart("" , null) // StringUtil.removeStart(null , "abc") // null StringUtil.removeStart("" , "") // StringUtil.removeStart("abc" , "") // abc StringUtil.removeStart("" , "abc") // StringUtil.removeStart("abcdef", "c") // abcdef StringUtil.removeStart("abcdef", "C") // abcdef StringUtil.removeStart("abcdef", "C", false) // abcdef StringUtil.removeStart("ABcdef", "aB") // ABcdef StringUtil.removeStart("ABcdef", "aB", false) // cdef StringUtil.removeStart("ABcdeF", "Ef") // ABcdeF StringUtil.removeStart("ABcdeF", "Ef", false) // ABcdeF StringUtil.removeStart("abcdef", "ab") // cdef StringUtil.removeStart("abcdef", "abcdef") // StringUtil.removeStart("abcdef", "abcdefg") // abcdef
replaceExtended | () | method |
public static function replaceExtended(str:String, find:String, replaceBy:String, stringCase:StringCase):String
Search for all occurrences of the String
find
within the String
str
and replaces by the String
replaceBy
.
Parameters
str:String — the String object to search. May be null .
| |
find:String — the String object to search for and replace. May be null .
| |
replaceBy:String — the String object that will replace the String find .
| |
stringCase:StringCase — indicates whether case sensitivity is considered or not in the comparison.
|
String — the String str with the String find replaced by the String replaceBy . If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.replaceExtended(null , null , "x") // null StringUtil.replaceExtended("" , null , "x") // StringUtil.replaceExtended(null , "abc", "x") // null StringUtil.replaceExtended("" , "" , "x") // StringUtil.replaceExtended("abc" , "" , "x") // abc StringUtil.replaceExtended("" , "abc", "x") // StringUtil.replaceExtended("abcdefabca", "a" , "x") // xbcdefxbcx StringUtil.replaceExtended("AbcdefabcA", "a" , "x") // AbcdefxbcA StringUtil.replaceExtended("AbcdefabcA", "a" , "x", false) // xbcdefxbcx StringUtil.replaceExtended("abcdef" , "y" , "x") // abcdef
reverse | () | method |
public static function reverse(str:String):String
Reverses the chars of the String
object.
Parameters
str:String — the String object to reverse. May be null .
|
String — the String object with the chars reversed. If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.reverse(null) // null StringUtil.reverse("") // StringUtil.reverse(" ") // StringUtil.reverse("a") // a StringUtil.reverse("ab") // ba StringUtil.reverse("abc") // cba StringUtil.reverse(" abc") // cba StringUtil.reverse(" abc ") // cba StringUtil.reverse("abc\td") // d\tcba
rtrim | () | method |
public static function rtrim(str:String):String
Removes control characters(char <= 32) from the start of the String
object.
Parameters
str:String — the String object to be trimmed. May be null .
|
String — the trimmed String object. If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.rtrim(null) // null StringUtil.rtrim("") // StringUtil.rtrim(" ") // StringUtil.rtrim("abc") // abc StringUtil.rtrim(" abc") // abc StringUtil.rtrim(" abc ") // abc StringUtil.rtrim(" abc ") // abc StringUtil.rtrim(" \n\t abc ") // \n\t abc StringUtil.rtrim(" \n\t abc \n\t ") // \n\t abc
startsWith | () | method |
public static function startsWith(str:String, prefix:String, stringCase:StringCase):Boolean
Check if the String
object starts with a specified prefix.
Parameters
str:String — the String object to check. May be null .
| |
prefix:String — the prefix to find. May be null .
| |
stringCase:StringCase — indicates whether case sensitivity is considered or not in the comparison.
|
Boolean — true if the String object starts with the prefix or if both arguments are null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.startsWith(null , null) // true StringUtil.startsWith("" , null) // false StringUtil.startsWith(null , "abc") // false StringUtil.startsWith("abcdef", "a") // true StringUtil.startsWith("abcdef", "A") // false StringUtil.startsWith("abcdef", "A", false) // true StringUtil.startsWith("ABcdef", "aB") // false StringUtil.startsWith("ABcdef", "aB", false) // true StringUtil.startsWith("abcdef", "ab") // true StringUtil.startsWith("abcdef", "abcdef") // true StringUtil.startsWith("abcdef", "abcdefg") // false
trim | () | method |
public static function trim(str:String):String
Removes control characters(char <= 32) from the start and end of the String
object.
Parameters
str:String — the String object to be trimmed. May be null .
|
String — the trimmed String object. If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.trim(null) // null StringUtil.trim("") // StringUtil.trim(" ") // StringUtil.trimToEmpty(" \t ") // StringUtil.trim("abc") // abc StringUtil.trim(" abc") // abc StringUtil.trim(" abc ") // abc StringUtil.trim(" abc ") // abc StringUtil.trim(" \n\t abc ") // abc StringUtil.trim(" \n\t abc \n\t ") // abc
trimToEmpty | () | method |
public static function trimToEmpty(str:String):String
Removes control characters(char <= 32) from the start and end of the String
object.
Parameters
str:String — the String object to be trimmed. May be null .
|
String — the trimmed String object. If the str argument is null then the return is an empty String ("").
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.trimToEmpty(null) // StringUtil.trimToEmpty("") // StringUtil.trimToEmpty(" ") // StringUtil.trimToEmpty(" ") // StringUtil.trimToEmpty(" \t ") // StringUtil.trimToEmpty("abc") // abc StringUtil.trimToEmpty(" abc") // abc StringUtil.trimToEmpty(" abc ") // abc StringUtil.trimToEmpty(" abc ") // abc StringUtil.trimToEmpty(" \n\t abc ") // abc StringUtil.trimToEmpty(" \n\t abc \n\t ") // abc
trimToNull | () | method |
public static function trimToNull(str:String):String
Removes control characters(char <= 32) from the start and end of the String
object.
Parameters
str:String — the String object to be trimmed. May be null .
|
String — the trimmed String object if it contains any characters that isn't control characters(char <= 32), or null if it contains only those characters. If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.trimToNull(null) // null StringUtil.trimToNull("") // null StringUtil.trimToNull(" ") // null StringUtil.trimToNull(" ") // null StringUtil.trimToNull(" \t ") // null StringUtil.trimToNull("abc") // abc StringUtil.trimToNull(" abc") // abc StringUtil.trimToNull(" abc ") // abc StringUtil.trimToNull(" abc ") // abc StringUtil.trimToNull(" \n\t abc ") // abc StringUtil.trimToNull(" \n\t abc \n\t ") // abc
uncapitalize | () | method |
public static function uncapitalize(str:String):String
Uncapitalizes a String
object, changing only the first letter to lowercase.
Parameters
str:String — the String object to uncapitalize. May be null .
|
String — the uncapitalized String . If the str argument is null then the return is null .
|
import org.as3coreaddendum.utils.StringUtil; StringUtil.uncapitalize(null) // null StringUtil.uncapitalize(" ") // StringUtil.uncapitalize("a") // a StringUtil.uncapitalize("A") // a StringUtil.uncapitalize("ab") // ab StringUtil.uncapitalize("Ab") // ab StringUtil.uncapitalize("aB") // aB StringUtil.uncapitalize("AB") // aB StringUtil.uncapitalize("abc") // abc StringUtil.uncapitalize(" abc") // abc StringUtil.uncapitalize(" Abc") // Abc