Packagenet.guttershark.util
Classpublic final class StringUtils

The StringUtils class is a singleton that contains utility methods for strings.



Public Methods
 MethodDefined by
  
afterFirst(search:String, returnAfter:String):String
Returns everything after the first occurrence of the provided character in the string.
StringUtils
  
afterLast(search:String, returnAfter:String):String
Returns everything after the last occurence of the provided character in the string.
StringUtils
  
beforeFirst(search:String, returnBefore:String):String
Returns everything before the first occurrence of the provided character in the string.
StringUtils
  
beforeLast(search:String, returnBefore:String):String
Returns everything before the last occurrence of the provided character in the string.
StringUtils
  
beginsWith(input:String, prefix:String):Boolean
Determines whether the specified string begins with the specified prefix.
StringUtils
  
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.
StringUtils
  
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.
StringUtils
  
capitalize(p_string:String, allWords:Boolean = false):String
Capitallizes the first word in a string, and optionally all words.
StringUtils
  
commaFormatNumber(nm:Object):String
Format a number with commas - ie.
StringUtils
  
countOf(search:String, pattern:String, caseSensitive:Boolean = true):uint
Determines the number of times a charactor or sub-string appears within the string.
StringUtils
  
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.
StringUtils
  
encodeNumber(strNumber:String, digitsShown:uint, encodeChar:String):String
Encode a credit card number as a string and encode all digits except the last digitsShown.
StringUtils
  
endsWith(input:String, suffix:String):Boolean
Determines whether the specified string ends with the specified suffix.
StringUtils
  
equals(s1:String, s2:String, caseSensitive:Boolean = false):Boolean
Does a case insensitive compare with two strings.
StringUtils
  
findFileType(source:String):String
Find the file type from a source path.
StringUtils
  
firstToUpper(str:String):String
Capitalize the first character in the string.
StringUtils
  
floatToString(n:Number):String
Remove scientific notation from very small floats when casting to String.
StringUtils
  
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).
StringUtils
  
Get an array of 50 state abbreviations.
StringUtils
  
[static] Singleton access.
StringUtils
  
hasBr(str:String):Boolean
Detect HTML line breaks (>br<).
StringUtils
  
htmlDecode(s:String):String
Decode HTML.
StringUtils
  
htmlEncode(s:String):String
Encode HTML.
StringUtils
  
isemail(str:String):Boolean
Check whether a string is a valid email.
StringUtils
  
isfileuri(str:String):Boolean
Check whether or not a string is a valid file URI.
StringUtils
  
isphone(str:String):Boolean
Check whether or not a string is a valid phone number.
StringUtils
  
ispobox(address:String):Boolean
Check whether a string is a valid po box.
StringUtils
  
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.
StringUtils
  
isurl(str:String):Boolean
Check that a string is a valid http URL.
StringUtils
  
isValidCCExDate(month:int, year:int):Boolean
Validate a credit card's expiration date.
StringUtils
  
isValidCCNumber(strNumber:String):Boolean
Validate a credit card number.
StringUtils
  
ltrim(str:String):String
Removes whitespace from the front of the specified string.
StringUtils
  
padLeft(str:String, char:String, length:uint):String
Pads a string with the specified character to a specified length from the left.
StringUtils
  
padRight(str:String, char:String, length:uint):String
Pads a string with the specified character to a specified length from the right.
StringUtils
  
padZeroOnFloat(n:Number):String
Add zero in front of floated number.
StringUtils
  
properCase(str:String):String
Properly cases the string in "sentence format".
StringUtils
  
randChar(amount:Number):String
Generate a set of random characters.
StringUtils
  
randLowerChar(amount:Number):String
Generate a set of random LowerCase characters.
StringUtils
  
randNum(amount:Number):String
Generate a set of random Number characters.
StringUtils
  
randSpecialChar(amount:Number):String
Generate a set of random Special and Number characters.
StringUtils
  
remove(search:String, pattern:String, caseSensitive:Boolean = true):String
Removes all instances of a pattern in the search string.
StringUtils
  
removeSpaces(str:String):String
Remove spaces from a string.
StringUtils
  
removeTabs(str:String):String
Remove tabs from a string.
StringUtils
  
replace(str:String, oldChar:String, newChar:String):String
Replace every instance of a string with something else
StringUtils
  
reverse(str:String):String
Returns the string in reverse order.
StringUtils
  
reverseWords(str:String):String
Returns the specified string in reverse word order.
StringUtils
  
rtrim(str:String):String
Removes whitespace from the end of a string.
StringUtils
  
sanitizeNull(str:String):String
Sanitize null strings for display purposes.
StringUtils
  
search(str:String, key:String, caseSensitive:Boolean = true):Boolean
Search for key in string.
StringUtils
  
similarity(source:String, target:String):Number
Determines the percentage of similiarity, based on editDistance.
StringUtils
  
stripTags(str:String):String
Removes all < and > based tags from a string
StringUtils
  
stripZeroAndRepairFloat(n:Number):String
Strip the zero off floated numbers and remove Scientific Notation.
StringUtils
  
stripZeroOnFloat(n:Number):String
Strip the zero off floated numbers.
StringUtils
  
swapCase(str:String):String
Swaps the casing of a string.
StringUtils
  
toBoolean(s:String):Boolean
Convert string or number to boolean
StringUtils
  
toDoubleQuote(str:String):String
Convert single quotes to double quotes.
StringUtils
  
toLowerCamel(str:String):String
Lower Camel Case a string.
StringUtils
  
toNumeric(str:String):String
Remove all formatting and return cleaned numbers from string.
StringUtils
  
toSingleQuote(str:String):String
Convert double quotes to single quotes.
StringUtils
  
toTitleCase(str:String):String
Transforms source String to per word capitalization.
StringUtils
  
trim(str:String):String
Remove leading & trailing white space.
StringUtils
  
trimall(str:String):String
Remove whitespace, line feeds, carrige returns from a string.
StringUtils
  
trimLeft(str:String):String
Removes whitespace from the front the specified string.
StringUtils
  
trimRight(str:String):String
Removes whitespace from the end of the specified string.
StringUtils
  
truncate(str:String, len:uint, suffix:String = "..."):String
Returns a string truncated to a specified length with optional suffix
StringUtils
  
wordCount(str:String):uint
Determines the number of words in a string.
StringUtils
Method detail
afterFirst()method
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
String
afterLast()method 
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
String
beforeFirst()method 
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
String
beforeLast()method 
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
String
beginsWith()method 
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
Boolean
between()method 
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
String
block()method 
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
Array — Array
capitalize()method 
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
String
commaFormatNumber()method 
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
String
countOf()method 
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
uint
editDistance()method 
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
uint
encodeNumber()method 
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
String
endsWith()method 
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
Boolean
equals()method 
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
Boolean
findFileType()method 
public function findFileType(source:String):String

Find the file type from a source path.

Parameters
source:String — A full file url or path.

Returns
String
firstToUpper()method 
public function firstToUpper(str:String):String

Capitalize the first character in the string.

Parameters
str:String — The string.

Returns
String
floatToString()method 
public function floatToString(n:Number):String

Remove scientific notation from very small floats when casting to String.

Parameters
n:Number — The target number.

Returns
String

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
   

getExtendedStateAbbreviationsArray()method 
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
Array
getStateAbbreviationsArray()method 
public function getStateAbbreviationsArray():Array

Get an array of 50 state abbreviations.

Returns
Array
gi()method 
public static function gi():StringUtils

Singleton access.

Returns
StringUtils
hasBr()method 
public function hasBr(str:String):Boolean

Detect HTML line breaks (>br<).

Parameters
str:String — The target string.

Returns
Boolean
htmlDecode()method 
public function htmlDecode(s:String):String

Decode HTML.

Parameters
s:String — The target string that has HTML in it.

Returns
String
htmlEncode()method 
public function htmlEncode(s:String):String

Encode HTML.

Parameters
s:String — The target string that has HTML in it.

Returns
String
isemail()method 
public function isemail(str:String):Boolean

Check whether a string is a valid email.

Parameters
str:String — The email to evaluate.

Returns
Boolean
isfileuri()method 
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
Boolean
isphone()method 
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
Boolean
ispobox()method 
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
Boolean
isStateAbbrev()method 
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
Boolean
isurl()method 
public function isurl(str:String):Boolean

Check that a string is a valid http URL.

Parameters
str:String — The string to evaluate.

Returns
Boolean
isValidCCExDate()method 
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
Boolean
isValidCCNumber()method 
public function isValidCCNumber(strNumber:String):Boolean

Validate a credit card number.

Parameters
strNumber:String — Credit card number as string.

Returns
Boolean
ltrim()method 
public function ltrim(str:String):String

Removes whitespace from the front of the specified string.

Parameters
str:String — The target string.

Returns
String
padLeft()method 
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
String
padRight()method 
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
String
padZeroOnFloat()method 
public function padZeroOnFloat(n:Number):String

Add zero in front of floated number.

Parameters
n:Number — The target number.

Returns
String
properCase()method 
public function properCase(str:String):String

Properly cases the string in "sentence format".

Parameters
str:String — The string to proper case.

Returns
String
randChar()method 
public function randChar(amount:Number):String

Generate a set of random characters.

Parameters
amount:Number — The number of characters to generate.

Returns
String
randLowerChar()method 
public function randLowerChar(amount:Number):String

Generate a set of random LowerCase characters.

Parameters
amount:Number — The number of characters to generate.

Returns
String
randNum()method 
public function randNum(amount:Number):String

Generate a set of random Number characters.

Parameters
amount:Number — The amount of numbers to generate.

Returns
String
randSpecialChar()method 
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
String
remove()method 
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
String
removeSpaces()method 
public function removeSpaces(str:String):String

Remove spaces from a string.

Parameters
str:String — The target string.

Returns
String
removeTabs()method 
public function removeTabs(str:String):String

Remove tabs from a string.

Parameters
str:String — The target string.

Returns
String
replace()method 
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
String
reverse()method 
public function reverse(str:String):String

Returns the string in reverse order.

Parameters
str:String — The String that will be reversed.

Returns
String
reverseWords()method 
public function reverseWords(str:String):String

Returns the specified string in reverse word order.

Parameters
str:String — The String that will be reversed.

Returns
String
rtrim()method 
public function rtrim(str:String):String

Removes whitespace from the end of a string.

Parameters
str:String — The target string.

Returns
String
sanitizeNull()method 
public function sanitizeNull(str:String):String

Sanitize null strings for display purposes.

Parameters
str:String — The string.

Returns
String
search()method 
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
Boolean
similarity()method 
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
Number
stripTags()method 
public function stripTags(str:String):String

Removes all < and > based tags from a string

Parameters
str:String — The source string.

Returns
String
stripZeroAndRepairFloat()method 
public function stripZeroAndRepairFloat(n:Number):String

Strip the zero off floated numbers and remove Scientific Notation.

Parameters
n:Number — The target number.

Returns
String
stripZeroOnFloat()method 
public function stripZeroOnFloat(n:Number):String

Strip the zero off floated numbers.

Parameters
n:Number — The target number.

Returns
String
swapCase()method 
public function swapCase(str:String):String

Swaps the casing of a string.

Parameters
str:String — The source string.

Returns
String
toBoolean()method 
public function toBoolean(s:String):Boolean

Convert string or number to boolean

Parameters
s:String — The string ("1", "true", "yes", "on").

Returns
Boolean

Example
Using toBoolean:
 
   var utils:Utilities = Utilities.gi();
   var b:Boolean = utils.convert.toBoolean("true");
   

toDoubleQuote()method 
public function toDoubleQuote(str:String):String

Convert single quotes to double quotes.

Parameters
str:String — The target string.

Returns
String
toLowerCamel()method 
public function toLowerCamel(str:String):String

Lower Camel Case a string.

Parameters
str:String — The target string.

Returns
String
toNumeric()method 
public function toNumeric(str:String):String

Remove all formatting and return cleaned numbers from string.

Parameters
str:String — The target string.

Returns
String

Example
Using the StringUtils.toNumeric method:
 
   var utils:Utilities = Utilities.gi();
   utils.string.toNumeric("123-123-1234"); //returns 1221231234 
   

toSingleQuote()method 
public function toSingleQuote(str:String):String

Convert double quotes to single quotes.

Parameters
str:String — The target string.

Returns
String
toTitleCase()method 
public function toTitleCase(str:String):String

Transforms source String to per word capitalization.

Parameters
str:String — The target string.

Returns
String
trim()method 
public function trim(str:String):String

Remove leading & trailing white space.

Parameters
str:String — The target string.

Returns
String
trimall()method 
public function trimall(str:String):String

Remove whitespace, line feeds, carrige returns from a string.

Parameters
str:String — The target string.

Returns
String
trimLeft()method 
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
String
trimRight()method 
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
String
truncate()method 
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
String
wordCount()method 
public function wordCount(str:String):uint

Determines the number of words in a string.

Parameters
str:String — The string.

Returns
uint