Packageimpression.utilities
Classpublic class StringUtils
InheritanceStringUtils Inheritance Object

The StringUtils class provides string-related utility methods.



Public Methods
 MethodDefined By
  
beginsWith(source:String, item:String):Boolean
[static] Returns true if source begins with item.
StringUtils
  
contains(source:String, item:String):Boolean
[static] Returns true if item is contained within source, ignoring case.
StringUtils
  
endsWith(source:String, item:String):Boolean
[static] Returns true if source ends with item.
StringUtils
  
formatString(format:String, ... args):String
[static] Replaces the format item in a string with the string representation of a corresponding object from the passed array.
StringUtils
  
isNullOrEmpty(source:String):Boolean
[static] Returns true if the passed string is null or the empty string ("").
StringUtils
  
isWhitespace(char:String):Boolean
[static] Returns true if the passed char is a whitespace character.
StringUtils
  
keepBetweenExcluding(source:String, start:String, end:String):String
[static] Removes everything before and including the first occurrence of start and after and including the first occurrence of end from source and returns the modified string.
StringUtils
  
keepBetweenIncluding(source:String, start:String, end:String):String
[static] Removes everything before the first occurrence of start and after the first occurrence of end from source and returns the modified string.
StringUtils
  
keepBetweenOuterExcluding(source:String, start:String, end:String):String
[static] Removes everything before and including the first occurrence of start and after and including the last occurrence of end from source and returns the modified string.
StringUtils
  
keepBetweenOuterIncluding(source:String, start:String, end:String):String
[static] Removes everything before the first occurrence of start and after the last occurrence of end from source and returns the modified string.
StringUtils
  
leftTrim(source:String):String
[static] Removes all leading whitespace from source.
StringUtils
  
remove(source:String, item:String):String
[static] Removes the first occurrence of a substring from source and returns the modified string.
StringUtils
  
removeAfterFirst(source:String, item:String):String
[static] Removes everything after the first occurrence of item from source and returns the modified string.
StringUtils
  
removeAfterFirstIncluding(source:String, item:String):String
[static] Removes everything after and including the first occurrence of item from source and returns the modified string.
StringUtils
  
removeAfterLast(source:String, item:String):String
[static] Removes everything after the last occurrence of item from source and returns the modified string.
StringUtils
  
removeAfterLastIncluding(source:String, end:String):String
[static] Removes everything after and including the last occurrence of item from source and returns the modified string.
StringUtils
  
removeAll(source:String, item:String):String
[static] Removes all occurrences of a substring from source and returns the modified string.
StringUtils
  
removeAllBetweenIncluding(source:String, start:String, end:String):String
[static] Removes all occurrences of the substring bound by start and end from source.
StringUtils
  
removeBeforeFirst(source:String, item:String):String
[static] Removes everything before the first occurrence of item from source and returns the modified string.
StringUtils
  
removeBeforeFirstIncluding(source:String, item:String):String
[static] Removes everything before and including the first occurrence of item from source and returns the modified string.
StringUtils
  
removeBetweenIncluding(source:String, start:String, end:String):String
[static] Removes everything from and including the first occurrence of start to the first occurrence of end from source and returns the modified string.
StringUtils
  
removeBetweenOuterIncluding(source:String, start:String, end:String):String
[static] Removes everything from and including the first occurrence of start to the last occurrence of end from source and returns the modified string.
StringUtils
  
removeLast(source:String, item:String):String
[static] Removes the last occurrence of a substring from source and returns the modified string.
StringUtils
  
replace(source:String, item:String, replace:String):String
[static] Replaces the first occurrence of a string with another string and returns the modified string.
StringUtils
  
replaceAll(source:String, item:String, replace:String):String
[static] Replaces all occurrences of a string with another string and returns the modified string.
StringUtils
  
rightTrim(source:String):String
[static] Removes all trailing whitespace from source.
StringUtils
  
splitFirst(item:String, delimiter:String):Array
[static] Returns an array with two strings.
StringUtils
  
trim(source:String):String
[static] Removes leading and trailing whitespace from source.
StringUtils
Method Detail
beginsWith()method
public static function beginsWith(source:String, item:String):Boolean

Returns true if source begins with item.

Parameters

source:String — The string to check.
 
item:String — The string to check the beginning of source for.

Returns
Booleantrue if source begins with item, false otherwise.
contains()method 
public static function contains(source:String, item:String):Boolean

Returns true if item is contained within source, ignoring case.

This function uses the String object's .toLowerCase() method to lower-case both strings, then returns the result of calling source.indexOf(item).

Parameters

source:String — The string to check.
 
item:String — The string to check for.

Returns
Booleantrue if item is contained within source, false else.
endsWith()method 
public static function endsWith(source:String, item:String):Boolean

Returns true if source ends with item.

Parameters

source:String — The string to check.
 
item:String — The string to check the end of source for.

Returns
Booleantrue if source ends with item, false otherwise.
formatString()method 
public static function formatString(format:String, ... args):String

Replaces the format item in a string with the string representation of a corresponding object from the passed array.

Parameters

format:String — The composite-format string to use. The composite format string should include any number of tokens of the form {[n]}, where n is a number from 0 to args.length - 1.
 
... args — The items to use to replace the tokens with.

Returns
String — The modified string.
isNullOrEmpty()method 
public static function isNullOrEmpty(source:String):Boolean

Returns true if the passed string is null or the empty string ("").

Parameters

source:String — The string to check.

Returns
Booleantrue if source is null or the empty string, false else.
isWhitespace()method 
public static function isWhitespace(char:String):Boolean

Returns true if the passed char is a whitespace character.

Whitespace characters are defined as carriage return (\r, character code 0x0D), line feed/newline (\n, character code 0x0A), tab (\t, character code 0x09), form feed (\f, character code 0x0C), and the space character ( , character code 0x20).

If the char.length property is greater than 1, then this function returns true only if all of the characters passed are whitespace characters.

If char is null or the char.length is 0, false is returned.

Parameters

char:String — The character to check.

Returns
Booleantrue if char is a whitespace character, false else.
keepBetweenExcluding()method 
public static function keepBetweenExcluding(source:String, start:String, end:String):String

Removes everything before and including the first occurrence of start and after and including the first occurrence of end from source and returns the modified string.

If source is null, null is returned. If start is not found, the empty string ("") will be returned. If end is not found, everything after and including start will be returned.

Parameters

source:String — The string to modify.
 
start:String — A string specifying the begining of the substring to keep.
 
end:String — A String specifying the end of the substring to keep.

Returns
String — A copy of source with everything everything before and including the first occurrence of start and after and including the first occurrence of end removed.

See also

keepBetweenIncluding()method 
public static function keepBetweenIncluding(source:String, start:String, end:String):String

Removes everything before the first occurrence of start and after the first occurrence of end from source and returns the modified string.

If source is null, null is returned. If start is not found, the empty string ("") will be returned. If end is not found, everything after and including start will be returned.

Parameters

source:String — The string to modify.
 
start:String — A string specifying the begining of the substring to keep.
 
end:String — A String specifying the end of the substring to keep.

Returns
String — A copy of source with everything everything before the first occurrence of start and after the first occurrence of end removed.

See also

keepBetweenOuterExcluding()method 
public static function keepBetweenOuterExcluding(source:String, start:String, end:String):String

Removes everything before and including the first occurrence of start and after and including the last occurrence of end from source and returns the modified string.

If source is null, null is returned. If start is not found, the empty string ("") will be returned. If end is not found, everything after and including start will be returned.

Parameters

source:String — The string to modify.
 
start:String — A string specifying the begining of the substring to keep.
 
end:String — A String specifying the end of the substring to keep.

Returns
String — A copy of source with everything everything before and including the first occurrence of start and after and including the last occurrence of end removed.

See also

keepBetweenOuterIncluding()method 
public static function keepBetweenOuterIncluding(source:String, start:String, end:String):String

Removes everything before the first occurrence of start and after the last occurrence of end from source and returns the modified string.

If source is null, null is returned. If start is not found, the empty string ("") will be returned. If end is not found, everything after and including start will be returned.

Parameters

source:String — The string to modify.
 
start:String — A string specifying the begining of the substring to keep.
 
end:String — A String specifying the end of the substring to keep.

Returns
String — A copy of source with everything everything before the first occurrence of start and after the last occurrence of end removed.

See also

leftTrim()method 
public static function leftTrim(source:String):String

Removes all leading whitespace from source.

Parameters

source:String — Required. The string to remove leading whitespace from.

Returns
String — A copy of source with leading whitespace removed.

See also

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

Removes the first occurrence of a substring from source and returns the modified string.

If source is null, then null is returned.

Parameters

source:String — The string to remove the first occurrence of item from.
 
item:String — The substring to remove.

Returns
String — A copy of source string with first occurrence of item removed.
removeAfterFirst()method 
public static function removeAfterFirst(source:String, item:String):String

Removes everything after the first occurrence of item from source and returns the modified string.

If source is null, then null is returned. If item is null or is not found, source is returned unmodified.

Parameters

source:String — The string to modify.
 
item:String — The substring to use to determine what to remove.

Returns
String — A copy of source with everything after the first occurrence of item removed.

See also

removeAfterFirstIncluding()method 
public static function removeAfterFirstIncluding(source:String, item:String):String

Removes everything after and including the first occurrence of item from source and returns the modified string.

If source is null, then null is returned. If item is null or is not found, source is returned unmodified.

Parameters

source:String — The string to modify.
 
item:String — The substring to use to determine what to remove.

Returns
String — A copy of source with everything after and including the first occurrence of item removed.

See also

removeAfterLast()method 
public static function removeAfterLast(source:String, item:String):String

Removes everything after the last occurrence of item from source and returns the modified string.

If source is null, then null is returned. If item is null or is not found, source is returned unmodified.

Parameters

source:String — The string to modify.
 
item:String — The substring to use to determine what to remove.

Returns
String — A copy of source with everything after the last occurrence of item removed.

See also

removeAfterLastIncluding()method 
public static function removeAfterLastIncluding(source:String, end:String):String

Removes everything after and including the last occurrence of item from source and returns the modified string.

If source is null, then null is returned. If item is null or is not found, source is returned unmodified.

Parameters

source:String — The string to modify.
 
end:String — The substring to use to determine what to remove.

Returns
String — A copy of source with everything after and including the last occurrence of item removed.

See also

removeAll()method 
public static function removeAll(source:String, item:String):String

Removes all occurrences of a substring from source and returns the modified string.

If source is null, then null is returned.

Parameters

source:String — The string to remove all occurrences of item from.
 
item:String — The substring to remove.

Returns
String — A copy of source string with all occurrences of item removed.

Throws
TypeError Cannot — access a property or method of a null object reference (TypeError).
removeAllBetweenIncluding()method 
public static function removeAllBetweenIncluding(source:String, start:String, end:String):String

Removes all occurrences of the substring bound by start and end from source.

This method iteratively calls removeBetweenIncluding until the return value from the call matches the previous return value from the call.

Parameters

source:String — The string to remove all occurrences of the substring bound by start and end from.
 
start:String — A string specifying the beginning of the substring to remove.
 
end:String — A string specifying the ending of the substring to remove.

Returns
String — A copy of source string with all occurrences of the substring bound by start and end removed.

See also

removeBeforeFirst()method 
public static function removeBeforeFirst(source:String, item:String):String

Removes everything before the first occurrence of item from source and returns the modified string.

If source is null, then null is returned. If item is null or is not found, the empty string ("") is returned.

Parameters

source:String — The string to modify.
 
item:String — The substring to use to determine what to remove.

Returns
String — A copy of source with everything before the first occurrence of item removed.

See also

removeBeforeFirstIncluding()method 
public static function removeBeforeFirstIncluding(source:String, item:String):String

Removes everything before and including the first occurrence of item from source and returns the modified string.

If source is null, then null is returned. If item is null or is not found, the empty string ("") is returned.

Parameters

source:String — The string to modify.
 
item:String — The substring to use to determine what to remove.

Returns
String — A copy of source with everything before and including the first occurrence of item removed.

See also

removeBetweenIncluding()method 
public static function removeBetweenIncluding(source:String, start:String, end:String):String

Removes everything from and including the first occurrence of start to the first occurrence of end from source and returns the modified string.

If source is null, then null is returned. If start is null, the empty string (""), or is not found, source is returned unmodified. If end is null, the empty string (""), is not found, or occurs before start, everything from start to the end of source is removed.

Parameters

source:String — The string to remove the substring bound by the first occurrences of start and end from.
 
start:String — A string specifying the beginning of the substring to remove from source.
 
end:String — A string specifying the ending of the substring to remove from source.

Returns
String — A copy of source string with everything from and including the first occurrence of start to the first occurrence of end removed.

See also

removeBetweenOuterIncluding()method 
public static function removeBetweenOuterIncluding(source:String, start:String, end:String):String

Removes everything from and including the first occurrence of start to the last occurrence of end from source and returns the modified string.

If source is null, then null is returned. If start is null, the empty string (""), or is not found, source is returned unmodified. If end is null, the empty string (""), is not found, or occurs before start, everything from start to the end of source is removed.

Parameters

source:String — The string to remove the substring bound by the first occurrence of start and the last occurrence of end from.
 
start:String — A string specifying the beginning of the substring to remove from source.
 
end:String — A string specifying the ending of the substring to remove from source.

Returns
String — A copy of source string with everything from and including the first occurrence of start to the last occurrence of end removed.

See also

removeLast()method 
public static function removeLast(source:String, item:String):String

Removes the last occurrence of a substring from source and returns the modified string.

If source is null, then null is returned.

Parameters

source:String — The string to remove the last occurrence of item from.
 
item:String — The substring to remove.

Returns
String — A copy of source string with last occurrence of item removed.
replace()method 
public static function replace(source:String, item:String, replace:String):String

Replaces the first occurrence of a string with another string and returns the modified string.

If source is null, null is returned.

Parameters

source:String — The string to modify.
 
item:String — The substring to replace.
 
replace:String — The substring to replace item with.

Returns
String — A copy of source with the first occurrence of item replaced with replace.

See also

replaceAll()method 
public static function replaceAll(source:String, item:String, replace:String):String

Replaces all occurrences of a string with another string and returns the modified string.

Parameters

source:String — The string to modify.
 
item:String — The substring to replace.
 
replace:String — The substring to replace item with.

Returns
String — A copy of source with all occurrences of item replaced with replace.

Throws
TypeError Cannot — access a property or method of a null object reference (TypeError).

See also

rightTrim()method 
public static function rightTrim(source:String):String

Removes all trailing whitespace from source.

Parameters

source:String — Required. The string to remove trailing whitespace from.

Returns
String — A copy of source with trailing whitespace removed.

See also

splitFirst()method 
public static function splitFirst(item:String, delimiter:String):Array

Returns an array with two strings. The first string contains everything in item up to the first occurrence of delimiter; the second string contains everying after the first occurrence of delimiter.

Parameters

item:String — The string to split.
 
delimiter:String — The substring to split item on.

Returns
Array — An array with two strings.
trim()method 
public static function trim(source:String):String

Removes leading and trailing whitespace from source.

Parameters

source:String — Required. The string to remove leading and trailing whitespace from.

Returns
String — A copy of source with leading and trailing whitespace removed.

See also