StringUtils
| Kind of class: | public class |
|---|---|
| Package: | com.trycatch.utils |
| Inherits from: | none |
| Known subclasses: | |
| Classpath: | com.trycatch.utils.StringUtils |
| File last modified: | Tuesday, 09 June 2009, 10:12:37 |
Summary
Constructor
- StringUtils : void
Constants
- VOWELS : String
- Vowels, includes y
Class properties
- debug : Boolean
- If true, each method will trace its name and the classes classPath when called.
- classPath : String
- LOWERCASE_LETTERS : String
- The alphabet in lowercase.
- UPPERCASE_LETTERS : String
- The alphabet in uppercase.
- CONSONANTS : String
- Consonants
- htmlentities : Array
- An array of all HTML entity codes.
- specialChars : Array
- An array of HTML special characters.
- US_STATE : Array
- An array of US States (in uppercase).
- US_STATE_ABBR : Array
- An array of US State abreviations (in uppercase).
- DIGITS : String
- A string of numeric digits 0-9.
- PHONENUMBER_DELIMITERS : String
- A string of valid phone number delimeters.
- EMAIL_CHARS : String
- A string of valid email message characters.
- NAME_SPECIAL_CHARS : String
- A string of valid name special characters.
- MINISCULE_WORDS : Array
- Default Array of words not capitilized by titleCase method.
- LINE_BREAK : String
Instance methods
- titleCase (str:String, ommitWords:Array) : String
- sentenceCase (s:String) : String
- htmlSpecialChars (s:String) : String
- htmlEntities (s:String) : String
- stripSpecialChars (s:String) : String
- isEmpty (s:String) : Boolean
- isNotEmpty (s:String) : Boolean
- isWhitespace (s:String) : Boolean
- Checks to see if a String is composed of whitespace characters or is empty.
- isNotWhitespace (s:String) : Boolean
- The reverse of isWhitespace.
- stripWhitespace (str:String) : String
- stripLeadingWhitespace (str:String) : String
- stripTrailingWhitespace (str:String) : String
- stripAllWhitespace (s:String) : String
- stripWordSpace (str:String) : String
- stripCharsInBag (s:String, bag:String) : String
- stripTags (s:String) : String
- stripCharsNotInBag (s:String, bag:String) : String
- matchCharsInBag (s:String, bag:String) : Boolean
- generateRandomString (_length:int, _useUpperCase:Boolean = true, _useLowerCase:Boolean = true, _useNumbers:Boolean = true) : String
- Generates a random string of the supplied length
- generateTruelyUniqueNumericString : String
- Generates and returns a truely random numeric string
Constructor
StringUtils
public function StringUtils (
) : void
Constants
VOWELS
public static const VOWELS:String = "AEIOUY"
(read)
Vowels, includes y
Class properties
classPath
public static classPath:String = "com.nemo.utils.StringUtils"
(read,write)
CONSONANTS
public static CONSONANTS:String = "ABCDFGHJKLMNPQRSTVWXZ"
(read,write)
Consonants
debug
public static debug:Boolean = false
(read,write)
If true, each method will trace its name and the classes classPath when called.
See also:
DIGITS
public static DIGITS:String = "0123456789"
(read,write)
A string of numeric digits 0-9.
EMAIL_CHARS
public static EMAIL_CHARS:String = DIGITS + LOWERCASE_LETTERS + UPPERCASE_LETTERS + ".&+-_?^~"
(read,write)
A string of valid email message characters.
See also:
htmlentities
public static htmlentities:Array
(read,write)
An array of all HTML entity codes.
LINE_BREAK
public static LINE_BREAK:String = String.fromCharCode(10)
(read,write)
LOWERCASE_LETTERS
public static LOWERCASE_LETTERS:String = "abcdefghijklmnopqrstuvwxyz"
(read,write)
The alphabet in lowercase.
MINISCULE_WORDS
public static MINISCULE_WORDS:Array
(read,write)
Default Array of words not capitilized by titleCase method.
Default value:
Default value:
["and","the","in","an","or","at","of","a"]. NAME_SPECIAL_CHARS
public static NAME_SPECIAL_CHARS:String = " -'."
(read,write)
A string of valid name special characters.
PHONENUMBER_DELIMITERS
public static PHONENUMBER_DELIMITERS:String = "()- ./"
(read,write)
A string of valid phone number delimeters.
specialChars
public static specialChars:Array
(read,write)
An array of HTML special characters.
UPPERCASE_LETTERS
public static UPPERCASE_LETTERS:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
(read,write)
The alphabet in uppercase.
US_STATE
public static US_STATE:Array
(read,write)
An array of US States (in uppercase).
US_STATE_ABBR
public static US_STATE_ABBR:Array
(read,write)
An array of US State abreviations (in uppercase).
Instance methods
generateRandomString
public function generateRandomString (
_length:int,
_useUpperCase:Boolean = true,
_useLowerCase:Boolean = true,
_useNumbers:Boolean = true) : String
Generates a random string of the supplied length
Parameters:
_useUpperCase:
Whether or not to use uppercase letters
_useLowerCase:
Whether or not to use lowercase letters
_useNumbers :
Whether or not to use numbers
Returns:
- A random String
generateTruelyUniqueNumericString
public function generateTruelyUniqueNumericString (
) : String
Generates and returns a truely random numeric string
Returns:
- A random numeric string
See also:
htmlEntities
public function htmlEntities (
s:String) : String
Parameters:
The:
string to convert HTML entities to special characters.
Returns:
- The supplied string with all HTML entities converted to special characters.
htmlSpecialChars
public function htmlSpecialChars (
s:String) : String
Parameters:
s:
The string to convert html special characters to html special entities.
Returns:
- The supplied string with all HTML special characters converted to special characters.
isEmpty
public function isEmpty (
s:String) : Boolean
Parameters:
s:
The string to evaluate whether or not its empty.
Returns:
- Boolean, whether or not the supplied string is empty.
isNotEmpty
public function isNotEmpty (
s:String) : Boolean
Parameters:
s:
The string to evaluate whether or not its empty.
Returns:
- Boolean, whehter or not the supplied string is empty.
isNotWhitespace
public function isNotWhitespace (
s:String) : Boolean
The reverse of isWhitespace.
Parameters:
s:
The string to determine whether or not it is entirely whitespace.
Returns:
- Boolean true if at least one character in the string is not a space, tab, newline, or other whitespace character. False if the string is composed entirely of whitespace chars, or if it is empty.
isWhitespace
public function isWhitespace (
s:String) : Boolean
Checks to see if a String is composed of whitespace characters or is empty.
Parameters:
s:
The string to determine whether or not it is entirely whitespace.
Returns:
- Boolean true if the string is composed entirely of whitespace chars, or if it is empty. False if at least one character in the string is not a space, tab, newline, or other whitespace character.
matchCharsInBag
public function matchCharsInBag (
s:String,
bag:String) : Boolean
Parameters:
s :
The string evaluate whether or not its composed of only characters in second parameter.
bag:
The characters to evaluate whehter or not the first parameter is composed entirely of.
Returns:
- Boolean, true if s is composed only of characters in bag.
sentenceCase
public function sentenceCase (
s:String) : String
Parameters:
s:
The string to convert to senteceCase. Sentence case runs stripWordSpace, then captilizes the first word of each sentece.
Returns:
- The supplied string converted to senteceCase.
stripAllWhitespace
public function stripAllWhitespace (
s:String) : String
Parameters:
s:
The string to remove all whitespace from.
Returns:
- The supplied string with all whitespace removed.
stripCharsInBag
public function stripCharsInBag (
s:String,
bag:String) : String
Parameters:
s :
The string to remove characters from.
bag:
The characters to remove from s, the first parameter.
Returns:
- The first parameter with all characters in second parameter removed.
stripCharsNotInBag
public function stripCharsNotInBag (
s:String,
bag:String) : String
Parameters:
s :
The string to remove characters from.
bag:
The characters not to remove from s, the first parameter.
Returns:
- The first parameter with all characters not in second parameter removed.
stripLeadingWhitespace
public function stripLeadingWhitespace (
str:String) : String
Parameters:
str:
The string to strip leading whitespace from.
Returns:
- The supplied string with leading whitespace removed.
stripSpecialChars
public function stripSpecialChars (
s:String) : String
Parameters:
s:
The string to srip special characters from. Special characters are &,",',<,>.
Returns:
- The supplied string with special characters removed.
stripTags
public function stripTags (
s:String) : String
Parameters:
s:
The string to strip tags from. Anything in between <> will be removed.
Returns:
- The supplied string with all tags removed.
stripTrailingWhitespace
public function stripTrailingWhitespace (
str:String) : String
Parameters:
str:
The string to remove trailing whitepsace from.
Returns:
- The supplied string with trailing whitespace removed.
stripWhitespace
public function stripWhitespace (
str:String) : String
Parameters:
str:
The string to strip trailing and leading whitespace from.
Returns:
- The supplied string with leading and trailing whitespace removed.
stripWordSpace
public function stripWordSpace (
str:String) : String
Parameters:
str:
The string to strip sequential spaces from.
Returns:
- The supplied string with seqential spaces removed.
titleCase
public function titleCase (
str:String,
ommitWords:Array) : String
Parameters:
str :
The string to convert to titleCase.
ommitWords:
An array of words to ommit from captilization. If no ommitting is desired, pass an empty Array like so:
StringUtils.titleCase("this is a sentence", []); // returns "This Is A Sentence"Returns:
- The supplied string converted to titleCase.
Example:
- titleCase with default ommit words.
StringUtils.titleCase("this is a sentence",StringUtils.MINISCULE_WORDS) // returns This is a Sentence
See also: