StringUtil

Kind of class:public class
Package:org.casalib.util
Inherits from:none
Version:09/06/09
Author:Aaron Clinger, Mike Creighton, David Nelson
Classpath:org.casalib.util.StringUtil
File last modified:Sunday, 06 September 2009, 12:04:52
Utilities for manipulating and searching Strings.

Summary


Constants
Class properties
Class methods
  • toTitleCase (source:String, lowerCaseSmallWords:Boolean = true) : String
    • Transforms source String to title case.
  • htmlEncode (source:String) : String
    • Converts all applicable characters to HTML entities.
  • htmlDecode (source:String) : String
    • Converts all HTML entities to their applicable characters.
  • isPunctuation (source:String, allowSpaces:Boolean = true) : Boolean
    • Determines if String is only comprised of punctuation characters (any character other than the letters or numbers).
  • isUpperCase (source:String) : Boolean
    • Determines if String is only comprised of upper case letters.
  • isLowerCase (source:String) : Boolean
    • Determines if String is only comprised of lower case letters.
  • isNumber (source:String) : Boolean
    • Determines if String is only comprised of numbers.
  • indexOfUpperCase (source:String, startIndex:uint = 0) : int
    • Searches the String for an occurrence of an upper case letter.
  • indexOfLowerCase (source:String, startIndex:uint = 0) : int
    • Searches the String for an occurrence of a lower case letter.
  • getNumbersFromString (source:String) : String
    • Returns all the numeric characters from a String.
  • getLettersFromString (source:String) : String
    • Returns all the letter characters from a String.
  • contains (source:String, search:String) : uint
    • Determines if String contains search String.
  • trimLeft (source:String, removeChars:String = StringUtil.WHITESPACE) : String
    • Strips whitespace (or other characters) from the beginning of a String.
  • trimRight (source:String, removeChars:String = StringUtil.WHITESPACE) : String
    • Strips whitespace (or other characters) from the end of a String.
  • trim (source:String, removeChars:String = StringUtil.WHITESPACE) : String
    • Strips whitespace (or other characters) from the beginning and end of a String.
  • removeExtraSpaces (source:String) : String
    • Removes additional spaces from String.
  • removeWhitespace (source:String) : String
    • Removes tabs, linefeeds, carriage returns and spaces from String.
  • remove (source:String, remove:String) : String
    • Removes characters from a source String.
  • replace (source:String, remove:String, replace:String) : String
    • Replaces target characters with new characters.
  • removeAt (source:String, position:int) : String
    • Removes a character at a specific index.
  • replaceAt (source:String, position:int, replace:String) : String
    • Replaces a character at a specific index with new characters.
  • addAt (source:String, position:int, addition:String) : String
    • Adds characters at a specific index.
  • getWordCount (source:String) : uint
    • Counts the number of words in a String.
  • getUniqueCharacters (source:String) : String
    • Extracts all the unique characters from a source String.

Constants

WHITESPACE

public static const WHITESPACE:String = ' \n\t\r'
(read)

Class properties

SMALL_WORDS

public static SMALL_WORDS:Array = new Array('a', 'an', 'and', 'as', 'at', 'but', 'by', 'en', 'for', 'if', 'is', 'in', 'of', 'on', 'or', 'the', 'to', 'v', 'via', 'vs')
(read,write)

Class methods

addAt

public static function addAt (
source:String, position:int, addition:String) : String

Adds characters at a specific index.
Parameters:
source :
String to add characters to.
position:
Position in which to add characters.
addition:
String to add.
Returns:
  • String with characters added.

contains

public static function contains (
source:String, search:String) : uint

Determines if String contains search String.
Parameters:
source:
String to search in.
search:
String to search for.
Returns:
  • Returns the frequency of the search term found in source String.

getLettersFromString

public static function getLettersFromString (
source:String) : String

Returns all the letter characters from a String.
Parameters:
source:
String to return letters from.
Returns:
  • String containing only letters.

getNumbersFromString

public static function getNumbersFromString (
source:String) : String

Returns all the numeric characters from a String.
Parameters:
source:
String to return numbers from.
Returns:
  • String containing only numbers.

getUniqueCharacters

public static function getUniqueCharacters (
source:String) : String

Extracts all the unique characters from a source String.
Parameters:
source:
String to find unique characters within.
Returns:
  • String containing unique characters from source String.

getWordCount

public static function getWordCount (
source:String) : uint

Counts the number of words in a String.
Parameters:
source:
String in which to count words.
Returns:
  • The amount of words.

htmlDecode

public static function htmlDecode (
source:String) : String

Converts all HTML entities to their applicable characters.
Parameters:
source:
String to convert.
Returns:
  • Returns the converted string.

htmlEncode

public static function htmlEncode (
source:String) : String

Converts all applicable characters to HTML entities.
Parameters:
source:
String to convert.
Returns:
  • Returns the converted string.

indexOfLowerCase

public static function indexOfLowerCase (
source:String, startIndex:uint = 0) : int

Searches the String for an occurrence of a lower case letter.
Parameters:
source:
String to search for a lower case letter.
Returns:
  • The index of the first occurrence of a lower case letter or -1.

indexOfUpperCase

public static function indexOfUpperCase (
source:String, startIndex:uint = 0) : int

Searches the String for an occurrence of an upper case letter.
Parameters:
source:
String to search for a upper case letter.
Returns:
  • The index of the first occurrence of a upper case letter or -1.

isLowerCase

public static function isLowerCase (
source:String) : Boolean

Determines if String is only comprised of lower case letters.
Parameters:
source:
String to check.
Returns:
  • Returns true if String is only lower case characters; otherwise false.
Usage note:
  • This function counts numbers, spaces, punctuation and special characters as lower case.

isNumber

public static function isNumber (
source:String) : Boolean

Determines if String is only comprised of numbers.
Parameters:
source:
String to check.
Returns:
  • Returns true if String is a number; otherwise false.

isPunctuation

public static function isPunctuation (
source:String, allowSpaces:Boolean = true) : Boolean

Determines if String is only comprised of punctuation characters (any character other than the letters or numbers).
Parameters:
source :
String to check.
allowSpaces:
Indicates to count spaces as punctuation true, or not to false.
Returns:
  • Returns true if String is only punctuation; otherwise false.

isUpperCase

public static function isUpperCase (
source:String) : Boolean

Determines if String is only comprised of upper case letters.
Parameters:
source:
String to check.
Returns:
  • Returns true if String is only upper case characters; otherwise false.
Usage note:
  • This function counts numbers, spaces, punctuation and special characters as upper case.

remove

public static function remove (
source:String, remove:String) : String

Removes characters from a source String.
Parameters:
source:
String to remove characters from.
remove:
String describing characters to remove.
Returns:
  • String with characters removed.

removeAt

public static function removeAt (
source:String, position:int) : String

Removes a character at a specific index.
Parameters:
source :
String to remove character from.
position:
Position of character to remove.
Returns:
  • String with character removed.

removeExtraSpaces

public static function removeExtraSpaces (
source:String) : String

Removes additional spaces from String.
Parameters:
source:
String to remove extra spaces from.
Returns:
  • String with additional spaces removed.

removeWhitespace

public static function removeWhitespace (
source:String) : String

Removes tabs, linefeeds, carriage returns and spaces from String.
Parameters:
source:
String to remove whitespace from.
Returns:
  • String with whitespace removed.

replace

public static function replace (
source:String, remove:String, replace:String) : String

Replaces target characters with new characters.
Parameters:
source :
String to replace characters from.
remove :
String describing characters to remove.
replace:
String to replace removed characters.
Returns:
  • String with characters replaced.

replaceAt

public static function replaceAt (
source:String, position:int, replace:String) : String

Replaces a character at a specific index with new characters.
Parameters:
source :
String to replace characters from.
position:
Position of character to replace.
replace :
String to replace removed character.
Returns:
  • String with character replaced.

toTitleCase

public static function toTitleCase (
source:String, lowerCaseSmallWords:Boolean = true) : String

Transforms source String to title case.
Parameters:
source :
String to return as title cased.
lowerCaseSmallWords:
Indicates to make small words lower case true, or to capitalized small words false.
Returns:
  • String with capitalized words.

trim

public static function trim (
source:String, removeChars:String = StringUtil.WHITESPACE) : String

Strips whitespace (or other characters) from the beginning and end of a String.
Parameters:
source :
String to remove characters from.
removeChars:
Characters to strip (case sensitive).
Returns:
  • String with characters removed.

trimLeft

public static function trimLeft (
source:String, removeChars:String = StringUtil.WHITESPACE) : String

Strips whitespace (or other characters) from the beginning of a String.
Parameters:
source :
String to remove characters from.
removeChars:
Characters to strip (case sensitive).
Returns:
  • String with characters removed.

trimRight

public static function trimRight (
source:String, removeChars:String = StringUtil.WHITESPACE) : String

Strips whitespace (or other characters) from the end of a String.
Parameters:
source :
String to remove characters from.
removeChars:
Characters to strip (case sensitive).
Returns:
  • String with characters removed.