Packagexp.utils
Classpublic class StringUtils

String utilities class Various string utilities

See also

support


Public Methods
 MethodDefined by
  
argbToHex(n:Number):String
[static] Converts an argb color to hex string
StringUtils
  
csvToArray(str:String, preserve:Boolean = true):Array
[static] Convert a simple CSV row string to an array Does not handle quoted strings with embedded comma's, use parseCSV instead
StringUtils
  
ellipsis(str:String, maxlen:int):String
[static] Formats a string to use ellipsis (...) if it exceeds maxlen
StringUtils
  
escapeHTML(str:String):String
[static] Escape HTML string
StringUtils
  
formatMessage(sections:*, ... rest):String
[static] Substitutes "{n}" tokens within the array of specified message sections and returns the concatenated string.
StringUtils
  
formatNationalPhoneNumber(p:String):String
[static] Formats an national phone number (123) 456 4444
StringUtils
  
formatPercent(r:Number, dp:int):String
[static] Formats a number as percentage For example (.50, 2) will be returned as 50.00%
StringUtils
  
formatPhoneNumber(p:String):String
[static] Formats an international phone number +999 123 456 4444
StringUtils
  
insertCharAt(str:String, char:String, i:int):String
[static] Insert text into a string at a given position
StringUtils
  
isDigit(ch:String):Boolean
[static] Determines if the character is a digit
StringUtils
  
isSpace(ch:String):Boolean
[static] Determines if the character is a space character
StringUtils
  
normalize(str:String):String
[static] Normalize whitespace in a string
StringUtils
  
parseCSVRecordset(data:String, firstRowHeader:Boolean = false, columns:Array = null, reverse:Boolean = false):Array
[static] Converts a CSV string to array of record objects.
StringUtils
  
parseCSVString(data:String):Array
[static] Converts a CSV string to a simple array of strings Handles quoted and non-quoted strings and embed commas
StringUtils
  
removeCharAt(str:String, start:int, end:int):String
[static] Remove a single or a series of characters starting at a given location in a string
StringUtils
  
repeatStr(str:String, repeat:int):String
[static] Returns a string containing a number of repetitions of str
StringUtils
  
replace(str:String, findStr:String, replaceStr:String = ""):String
[static] Replace text in a string with other text
StringUtils
  
replaceCharAt(str:String, char:String, start:int, end:int):String
[static] Replace a single or a series of character starting at a given location in a string
StringUtils
  
rgbToHex(n:Number):String
[static] Converts an rgb color to hex string
StringUtils
  
strip(str:String, findStr:String):String
[static] Strps all instance of findStr from a string
StringUtils
  
stripChars(str:String, chars:Array):String
[static] strip specified chars from a string
StringUtils
  
stripSpace(str:String):String
[static] Strip space from a string
StringUtils
  
substitute(message:String, ... rest):String
[static] Substitutes "{n}" tokens within the specified string with their respective arguments passed in.
StringUtils
  
trim(str:String, c:String):String
[static] Left and Right Trims a string of whitespace
StringUtils
  
trimLeft(str:String, c:String):String
[static] Left Trims a string of whitespace
StringUtils
  
trimRight(str:String, c:String):String
[static] Right Trims a string of whitespace
StringUtils
  
unescapeHTML(str:String):String
[static] Unescape HTML string
StringUtils
  
zeroPad(num:Number, digits:int, trailing:Boolean):String
[static] zero pads a string
StringUtils
Method detail
argbToHex()method
public static function argbToHex(n:Number):String

Converts an argb color to hex string

Parameters
n:Number — The number to convert

Returns
String — The formatted string
csvToArray()method 
public static function csvToArray(str:String, preserve:Boolean = true):Array

Convert a simple CSV row string to an array Does not handle quoted strings with embedded comma's, use parseCSV instead

Parameters
str:String — to be processed
 
preserve:Boolean (default = true) — if true preserves any whitespace otherwise it strips all whitespace

Returns
Array
ellipsis()method 
public static function ellipsis(str:String, maxlen:int):String

Formats a string to use ellipsis (...) if it exceeds maxlen

Parameters
str:String — The string to be formatted
 
maxlen:int — The maximum visble length of the string required

Returns
String
escapeHTML()method 
public static function escapeHTML(str:String):String

Escape HTML string

Parameters
str:String — to be processed

Returns
String
formatMessage()method 
public static function formatMessage(sections:*, ... rest):String

Substitutes "{n}" tokens within the array of specified message sections and returns the concatenated string.

Parameters
sections:* — An array of optional message sections to make subsitutions in. This string sections can contain special tokens of the form {n}, where n is a zero based index, that will be replaced with the additional parameters found at that index if specified. If all the values for a section are all null that section will be dropped from the final message string.
 
... rest — Optional array of values to be substituted

Returns
String — New string with all of the {n} tokens replaced with the respective arguments specified.
formatNationalPhoneNumber()method 
public static function formatNationalPhoneNumber(p:String):String

Formats an national phone number (123) 456 4444

Parameters
p:String — The phone number to format

Returns
String — The formatted phone number
formatPercent()method 
public static function formatPercent(r:Number, dp:int):String

Formats a number as percentage For example (.50, 2) will be returned as 50.00%

Parameters
r:Number — ratio a decimal value between 0 and 1
 
dp:int — decimal places

Returns
String — the formatted value
formatPhoneNumber()method 
public static function formatPhoneNumber(p:String):String

Formats an international phone number +999 123 456 4444

Parameters
p:String — The phone number to format

Returns
String — The formatted phone number
insertCharAt()method 
public static function insertCharAt(str:String, char:String, i:int):String

Insert text into a string at a given position

Parameters
str:String — The string to be processed
 
char:String — The character or string to be inserted
 
i:int — The index of the location to insert at

Returns
String
isDigit()method 
public static function isDigit(ch:String):Boolean

Determines if the character is a digit

Parameters
ch:String — Character to be processed

Returns
Boolean — True if the charactre is a digit
isSpace()method 
public static function isSpace(ch:String):Boolean

Determines if the character is a space character

Parameters
ch:String — Character to be processed

Returns
Boolean — True if the charactre is a digit
normalize()method 
public static function normalize(str:String):String

Normalize whitespace in a string

Parameters
str:String — to be processed

Returns
String
parseCSVRecordset()method 
public static function parseCSVRecordset(data:String, firstRowHeader:Boolean = false, columns:Array = null, reverse:Boolean = false):Array

Converts a CSV string to array of record objects. Handles quoted and non-quoted strings and embed commas

Parameters
data:String — The csv string to be parsed
 
firstRowHeader:Boolean (default = false) — If true it is assumed the first row in the recordset contains the namees of the columns
 
columns:Array (default = null) — If true the recordset is reversed.
 
reverse:Boolean (default = false)

Returns
Array — The recordset
parseCSVString()method 
public static function parseCSVString(data:String):Array

Converts a CSV string to a simple array of strings Handles quoted and non-quoted strings and embed commas

Parameters
data:String

Returns
Array
removeCharAt()method 
public static function removeCharAt(str:String, start:int, end:int):String

Remove a single or a series of characters starting at a given location in a string

Parameters
str:String — The string to be processed
 
start:int — The index of the location to remove at
 
end:int — The ending index of the location to remove. If not specified a single character is removed.

Returns
String
repeatStr()method 
public static function repeatStr(str:String, repeat:int):String

Returns a string containing a number of repetitions of str

Parameters
str:String
 
repeat:int

Returns
String — str concat repeat number of times
replace()method 
public static function replace(str:String, findStr:String, replaceStr:String = ""):String

Replace text in a string with other text

Parameters
str:String — The string to be processed
 
findStr:String — What to find in str
 
replaceStr:String (default = "") — The text to replace findStr

Returns
String
replaceCharAt()method 
public static function replaceCharAt(str:String, char:String, start:int, end:int):String

Replace a single or a series of character starting at a given location in a string

Parameters
str:String — The string to be processed
 
char:String — The new character or string to be used
 
start:int — The index of the location to replace at
 
end:int — The ending index of the location to replace. If not specified a single character is replaced.

Returns
String
rgbToHex()method 
public static function rgbToHex(n:Number):String

Converts an rgb color to hex string

Parameters
n:Number — The number to convert

Returns
String — The formatted string
strip()method 
public static function strip(str:String, findStr:String):String

Strps all instance of findStr from a string

Parameters
str:String — to be processed
 
findStr:String

Returns
String
stripChars()method 
public static function stripChars(str:String, chars:Array):String

strip specified chars from a string

Parameters
str:String
 
chars:Array

Returns
String
stripSpace()method 
public static function stripSpace(str:String):String

Strip space from a string

Parameters
str:String — to be processed

Returns
String
substitute()method 
public static function substitute(message:String, ... rest):String

Substitutes "{n}" tokens within the specified string with their respective arguments passed in.

Parameters
message:String — The string to make subsitutions in. This string can contain special tokens of the form {n}, where n is a zero based index, that will be replaced with the additional parameters found at that index if specified.
 
... rest — Optional array of values to be substituted

Returns
String — New string with all of the {n} tokens replaced with the respective arguments specified.
trim()method 
public static function trim(str:String, c:String):String

Left and Right Trims a string of whitespace

Parameters
str:String — The string to be trimmed
 
c:String — The character to trim by default it is the whitespace

Returns
String
trimLeft()method 
public static function trimLeft(str:String, c:String):String

Left Trims a string of whitespace

Parameters
str:String — The string to be trimmed
 
c:String — The character to trim by default it is the whitespace

Returns
String
trimRight()method 
public static function trimRight(str:String, c:String):String

Right Trims a string of whitespace

Parameters
str:String — The string to be trimmed
 
c:String — The character to trim by default it is the whitespace

Returns
String
unescapeHTML()method 
public static function unescapeHTML(str:String):String

Unescape HTML string

Parameters
str:String — to be processed

Returns
String
zeroPad()method 
public static function zeroPad(num:Number, digits:int, trailing:Boolean):String

zero pads a string

Parameters
num:Number — - the number to pad
 
digits:int — - the number of digits to pad to &
 
trailing:Boolean — - controls whether the padding is prefixed or suffixed

Returns
String — The formatted string