The StringUtils class is a singleton that
contains utility methods for strings.
public function afterFirst(search:String, returnAfter:String):String
Returns everything after the first occurrence of the provided character in the string.
Parameters
| search:String — The string to search in.
|
| |
| returnAfter:String — The string in which everything after the first occurance will be returned.
|
Returns
public function afterLast(search:String, returnAfter:String):String
Returns everything after the last occurence of the provided character in the string.
Parameters
| search:String — The string to search in.
|
| |
| returnAfter:String — The string in which everything after the last occurance will be returned.
|
Returns
public function beforeFirst(search:String, returnBefore:String):String
Returns everything before the first occurrence of the provided character in the string.
Parameters
| search:String — The string to search in.
|
| |
| returnBefore:String — The string in which everything before the first occurance will be returned.
|
Returns
public function beforeLast(search:String, returnBefore:String):String
Returns everything before the last occurrence of the provided character in the string.
Parameters
| search:String — The string.
|
| |
| returnBefore:String — The string in which everything before the last occurance will be returned.
|
Returns
public function beginsWith(input:String, prefix:String):Boolean
Determines whether the specified string begins with the specified prefix.
Parameters
| input:String — The string to search.
|
| |
| prefix:String — The prefix that will be tested against the string.
|
Returns
public function between(search:String, start:String, end:String):String
Returns everything after the first occurance of start and before the first occurrence of end in search.
Parameters
| search:String — The string to search in.
|
| |
| start:String — The string to use as the start index.
|
| |
| end:String — The string to use as the end index.
|
Returns
public function block(p_string:String, p_len:uint, p_delim:String = "."):Array
Utility method that intelligently breaks up your string,
allowing you to create blocks of readable text.
This method returns you the closest possible match to the p_delim paramater,
while keeping the text length within the p_len paramter.
If a match can't be found in your specified length an '...' is added to that block,
and the blocking continues untill all the text is broken apart.
Parameters
| p_string:String — The string to break up.
|
| |
| p_len:uint — Maximum length of each block of text.
|
| |
| p_delim:String (default = ".") — delimter to end text blocks on, default = '.'
|
Returns
public function capitalize(p_string:String, allWords:Boolean = false):String
Capitallizes the first word in a string, and optionally all words.
Parameters
| p_string:String — The string.
|
| |
| allWords:Boolean (default = false) — Whether or not all words will be capitalized.
|
Returns
public function commaFormatNumber(nm:Object):String
Format a number with commas - ie. 10000 -> 10,000
Parameters
| nm:Object — A Number or a String that will cast to a Number.
|
Returns
public function countOf(search:String, pattern:String, caseSensitive:Boolean = true):uint
Determines the number of times a charactor or sub-string appears within the string.
Parameters
| search:String — The string.
|
| |
| pattern:String — The character or sub-string to count.
|
| |
| caseSensitive:Boolean (default = true) — Whether or not the search is case sensitive.
|
Returns
public function editDistance(source:String, target:String):uint
Levenshtein distance (editDistance) is a measure of the similarity between two strings,
The distance is the number of deletions, insertions, or substitutions required to
transform a source into a target.
Parameters
| source:String — The source string.
|
| |
| target:String — The target string.
|
Returns
public function encodeNumber(strNumber:String, digitsShown:uint, encodeChar:String):String
Encode a credit card number as a string and encode all digits except the last digitsShown.
Parameters
| strNumber:String — credit card number as string
|
| |
| digitsShown:uint — display this many digits at the end of the card number for security purposes
|
| |
| encodeChar:String — optional encoding character to use instead of default '
|
Returns
public function endsWith(input:String, suffix:String):Boolean
Determines whether the specified string ends with the specified suffix.
Parameters
| input:String — The string to search.
|
| |
| suffix:String — The suffic that will be tested against the string.
|
Returns
public function equals(s1:String, s2:String, caseSensitive:Boolean = false):Boolean
Does a case insensitive compare with two strings.
Parameters
| s1:String — The first string.
|
| |
| s2:String — The second string.
|
| |
| caseSensitive:Boolean (default = false) — Whether or not the comparison is case sensitive.
|
Returns
public function findFileType(source:String):String
Find the file type from a source path.
Parameters
| source:String — A full file url or path.
|
Returns
public function firstToUpper(str:String):String
Capitalize the first character in the string.
Parameters
Returns
public function floatToString(n:Number):String
Remove scientific notation from very small floats when casting to String.
Parameters
| n:Number — The target number.
|
Returns
Example
Using the StringUtils.floatToString method:
var utils:Utilities = Utilities.gi();
trace(String(0.0000001)); //returns 1e-7
trace(utils.string.floatToString(0.0000001)); //returns .00000001
public function getExtendedStateAbbreviationsArray():Array
Returns an array of state abbreviations (50 states), plus
some extra according to the usps abbreviations list
(http://www.usps.com/ncsc/lookups/abbr_state.txt).
Returns
public function getStateAbbreviationsArray():Array
Get an array of 50 state abbreviations.
Returns
public static function gi():StringUtils
Singleton access.
Returns
public function hasBr(str:String):Boolean
Detect HTML line breaks (>br<).
Parameters
| str:String — The target string.
|
Returns
public function htmlDecode(s:String):String
Decode HTML.
Parameters
| s:String — The target string that has HTML in it.
|
Returns
public function htmlEncode(s:String):String
Encode HTML.
Parameters
| s:String — The target string that has HTML in it.
|
Returns
public function isemail(str:String):Boolean
Check whether a string is a valid email.
Parameters
| str:String — The email to evaluate.
|
Returns
public function isfileuri(str:String):Boolean
Check whether or not a string is a valid file URI.
Parameters
| str:String — The string to evaluate.
|
Returns
public function isphone(str:String):Boolean
Check whether or not a string is a valid phone number.
Parameters
| str:String — The string to evaluate.
|
Returns
public function ispobox(address:String):Boolean
Check whether a string is a valid po box. (PO ,P O,P.O,P. O,p o,p.o,p. o,Box,Post Office,post office).
Parameters
| address:String — The string to evaluate.
|
Returns
public function isStateAbbrev(state:String):Boolean
Check whether a state abbreviation is a valid state, according to the
usps list of abbreviations (http://www.usps.com/ncsc/lookups/abbr_state.txt) - including
military state abbreviations.
Parameters
| state:String — A state abbreviation to evaluate.
|
Returns
public function isurl(str:String):Boolean
Check that a string is a valid http URL.
Parameters
| str:String — The string to evaluate.
|
Returns
public function isValidCCExDate(month:int, year:int):Boolean
Validate a credit card's expiration date.
Parameters
| month:int — The month.
|
| |
| year:int — The year.
|
Returns
public function isValidCCNumber(strNumber:String):Boolean
Validate a credit card number.
Parameters
| strNumber:String — Credit card number as string.
|
Returns
public function ltrim(str:String):String
Removes whitespace from the front of the specified string.
Parameters
| str:String — The target string.
|
Returns
public function padLeft(str:String, char:String, length:uint):String
Pads a string with the specified character to a specified length from the left.
Parameters
| str:String — The string to pad.
|
| |
| char:String — Character for pad.
|
| |
| length:uint — Length to pad to.
|
Returns
public function padRight(str:String, char:String, length:uint):String
Pads a string with the specified character to a specified length from the right.
Parameters
| str:String — String to pad
|
| |
| char:String — Character for pad.
|
| |
| length:uint — Length to pad to.
|
Returns
public function padZeroOnFloat(n:Number):String
Add zero in front of floated number.
Parameters
| n:Number — The target number.
|
Returns
public function properCase(str:String):String
Properly cases the string in "sentence format".
Parameters
| str:String — The string to proper case.
|
Returns
public function randChar(amount:Number):String
Generate a set of random characters.
Parameters
| amount:Number — The number of characters to generate.
|
Returns
public function randLowerChar(amount:Number):String
Generate a set of random LowerCase characters.
Parameters
| amount:Number — The number of characters to generate.
|
Returns
public function randNum(amount:Number):String
Generate a set of random Number characters.
Parameters
| amount:Number — The amount of numbers to generate.
|
Returns
public function randSpecialChar(amount:Number):String
Generate a set of random Special and Number characters.
Parameters
| amount:Number — The number of characters to generate.
|
Returns
public function remove(search:String, pattern:String, caseSensitive:Boolean = true):String
Removes all instances of a pattern in the search string.
Parameters
| search:String — The string that will be checked for instances of remove string
|
| |
| pattern:String — The string that will be removed from the input string.
|
| |
| caseSensitive:Boolean (default = true) — Whether or not the replace is case sensitive.
|
Returns
public function removeSpaces(str:String):String
Remove spaces from a string.
Parameters
| str:String — The target string.
|
Returns
public function removeTabs(str:String):String
Remove tabs from a string.
Parameters
| str:String — The target string.
|
Returns
public function replace(str:String, oldChar:String, newChar:String):String
Replace every instance of a string with something else
Parameters
| str:String — The string to search in.
|
| |
| oldChar:String — The pattern to be removed.
|
| |
| newChar:String — The new string to instert.
|
Returns
public function reverse(str:String):String
Returns the string in reverse order.
Parameters
| str:String — The String that will be reversed.
|
Returns
public function reverseWords(str:String):String
Returns the specified string in reverse word order.
Parameters
| str:String — The String that will be reversed.
|
Returns
public function rtrim(str:String):String
Removes whitespace from the end of a string.
Parameters
| str:String — The target string.
|
Returns
public function sanitizeNull(str:String):String
Sanitize null strings for display purposes.
Parameters
Returns
public function search(str:String, key:String, caseSensitive:Boolean = true):Boolean
Search for key in string.
Parameters
| str:String — The target string.
|
| |
| key:String — The key to search for.
|
| |
| caseSensitive:Boolean (default = true) — Whether or not the search is case sensitive.
|
Returns
public function similarity(source:String, target:String):Number
Determines the percentage of similiarity, based on editDistance.
Parameters
| source:String — The source string.
|
| |
| target:String — The target string.
|
Returns
public function stripTags(str:String):String
Removes all < and > based tags from a string
Parameters
| str:String — The source string.
|
Returns
public function stripZeroAndRepairFloat(n:Number):String
Strip the zero off floated numbers and remove Scientific Notation.
Parameters
| n:Number — The target number.
|
Returns
public function stripZeroOnFloat(n:Number):String
Strip the zero off floated numbers.
Parameters
| n:Number — The target number.
|
Returns
public function swapCase(str:String):String
Swaps the casing of a string.
Parameters
| str:String — The source string.
|
Returns
public function toBoolean(s:String):Boolean
Convert string or number to boolean
Parameters
| s:String — The string ("1", "true", "yes", "on").
|
Returns
Example
Using toBoolean:
var utils:Utilities = Utilities.gi();
var b:Boolean = utils.convert.toBoolean("true");
public function toDoubleQuote(str:String):String
Convert single quotes to double quotes.
Parameters
| str:String — The target string.
|
Returns
public function toLowerCamel(str:String):String
Lower Camel Case a string.
Parameters
| str:String — The target string.
|
Returns
public function toNumeric(str:String):String
Remove all formatting and return cleaned numbers from string.
Parameters
| str:String — The target string.
|
Returns
Example
Using the StringUtils.toNumeric method:
var utils:Utilities = Utilities.gi();
utils.string.toNumeric("123-123-1234"); //returns 1221231234
public function toSingleQuote(str:String):String
Convert double quotes to single quotes.
Parameters
| str:String — The target string.
|
Returns
public function toTitleCase(str:String):String
Transforms source String to per word capitalization.
Parameters
| str:String — The target string.
|
Returns
public function trim(str:String):String
Remove leading & trailing white space.
Parameters
| str:String — The target string.
|
Returns
public function trimall(str:String):String
Remove whitespace, line feeds, carrige returns from a string.
Parameters
| str:String — The target string.
|
Returns
public function trimLeft(str:String):String
Removes whitespace from the front the specified string.
Parameters
| str:String — The String whose beginning whitespace will be removed.
|
Returns
public function trimRight(str:String):String
Removes whitespace from the end of the specified string.
Parameters
| str:String — The String whose ending whitespace will be removed.
|
Returns
public function truncate(str:String, len:uint, suffix:String = "..."):String
Returns a string truncated to a specified length with optional suffix
Parameters
| str:String — The string.
|
| |
| len:uint — The length the string should be shortend to.
|
| |
| suffix:String (default = "...") — The string to append to the end of the truncated string.
|
Returns
public function wordCount(str:String):uint
Determines the number of words in a string.
Parameters
Returns