StringUtils

Kind of class:class
Inherits from:none
Author:Stephan Bezoen
Classpath:org.asapframework.util.StringUtils
File last modified:Thursday, 16 November 2006, 14:13:41
A collection of String manipulation methods.
Specialized String methods can be found in StringUtilsTrim and StringUtilsSplit.

Summary


Class properties
Class methods
  • remove (inSource:String, inRemove:String) : String
    • Removes the specified string from a source string.
  • replace (inSource:String, inRemove:String, inReplace:String) : String
    • Replaces a string with another string.
  • format (inNumber:Number, inThouDelim:String, inDecDelim:String, inFillLength:Number, inFillChar:String) : String
    • Formats a number to a specific format.
  • appendDecimalString (inString:String, inAppendString:String, inDecimalPlaces:Number, inShouldDelimit:Boolean, inDecDelim:String) : String
    • Appends characters to a "stringified" number.
  • capitalizeChar (inString:String, inOffset:Number) : String
    • Transforms specific characters of string to uppercase, leaves rest untouched.
  • capitalizeString (inString:String) : String
    • Transforms the first character of string to uppercase, all others lowercase.
  • capitalizeWords (inString:String) : String
    • Transforms the first character of all words in a string to uppercase.
  • validateEmail (inAddress:String) : Boolean
    • Checks if an email address is correctly formed.

Class properties

CARRIAGE

static private CARRIAGE:Number = 13
(read)

LINEFEED

static private LINEFEED:Number = 10
(read)

SPACE

static private SPACE:Number = 32
(read)

TAB

static private TAB:Number = 9
(read)

Class methods

appendDecimalString

static function appendDecimalString (
inString:String, inAppendString:String, inDecimalPlaces:Number, inShouldDelimit:Boolean, inDecDelim:String) : String

Appends characters to a "stringified" number. For instance, "0" can have zeroes appended to 2 decimals after the fraction to make "0.00".
Parameters:
inString :
the text to append to
inAppendString :
the text to append
inDecimalPlaces:
the number of characters to append after the fraction character
inShouldDelimit:
(optional) if true, the resulting appending string is limited to the number of inDecimalPlaces; default false
inDecDelim :
(optional) the fraction character; "." if not specified
Example:
  • var myString:String = StringUtils.appendDecimalString("0", "0", 2); // "0.00"
    
    var myString:String = StringUtils.appendDecimalString("3.1", "0", 2); // "3.10"
    
    var myString:String = StringUtils.appendDecimalString("3.123456789", "12", 2, true); // "3.12"
    
    var myString:String = StringUtils.appendDecimalString("3", "0", 2, null, ","); // "3,00"

capitalizeChar

static function capitalizeChar (
inString:String, inOffset:Number) : String

Transforms specific characters of string to uppercase, leaves rest untouched.
Parameters:
inString:
String to convert
inOffset:
Number of character to convert to uppercase (zero based)
Returns:
  • Modified string.
Example:
  • StringUtils.capitalizeChar("this is a text", 8); // returns "this is A text"

capitalizeString

static function capitalizeString (
inString:String) : String

Transforms the first character of string to uppercase, all others lowercase.
Parameters:
inString:
String to convert
Returns:
  • Modified string.
Example:
  • StringUtils.capitalizeString("giMME a caP, pLEAsE"); // returns "Gimme a cap, please"

capitalizeWords

static function capitalizeWords (
inString:String) : String

Transforms the first character of all words in a string to uppercase.
Parameters:
inString:
String to convert
Returns:
  • Modified string.
Example:
  • StringUtils.capitalizeWords("gimme a CAP, please"); // returns "Gimme A Cap, Please"

format

static function format (
inNumber:Number, inThouDelim:String, inDecDelim:String, inFillLength:Number, inFillChar:String) : String

Formats a number to a specific format.
Parameters:
inNumber :
the number to format
inThouDelim :
(optional) the characters used to delimit thousands, millions, etcetera; "," if not specified
inDecDelim :
(optional) the characters used to delimit the fractional portion from the whole number; "." if not specified
inFillLength:
(optional) the number of leading characters to be added to the part *before* the decimals delimiter
inFillChar :
(optional) the character to use to fill with; zero ("0") if not specified
Returns:
  • A new formatted string.
Example:
  • StringUtils.format(169315625,"."); // returns 169.315.625
    
    StringUtils.format(1044.58364, ".", ",", 2); // returns 1.044,58364
    
    StringUtils.format(5234524.45, ".", ",", 9, "0"); // returns 005.234.524,45

remove

static function remove (
inSource:String, inRemove:String) : String

Removes the specified string from a source string.
Parameters:
source:
Text to remove from
remove:
String to remove
Returns:
  • Modified string.
Example:
  • StringUtils.remove("This is my String","my "); // returns "This is String"

replace

static function replace (
inSource:String, inRemove:String, inReplace:String) : String

Replaces a string with another string.
Parameters:
source :
Text to remove from
remove :
String to remove
replace:
Replacement string
Returns:
  • Modified string.
Example:
  • StringUtils.replace("This is my String", "my", "not a"); // returns "This is not a String"

validateEmail

static function validateEmail (
inAddress:String) : Boolean

Checks if an email address is correctly formed. It only checks position of the '@' and last '.'
Parameters:
inAddress:
A String containing an email address to be validated
Returns:
  • a Boolean, true if the email address is valid, otherwise false.