Packagesandy.util
Classpublic class StringUtil

Utility class for string manipulation.



Public Methods
 MethodDefined by
  
clear(p_sStr:String, p_aExpand:Array):String
[static] Removes '\r' '\n' and replaces multiple spaces with a single space.
StringUtil
  
clearRepeat(p_sStr:String, p_sRepeat:String, p_sReplace:String = ""):String
[static] Clears the source string from multiple occurences of a pattern.
StringUtil
  
findBlockIndex(p_sStr:String, p_sStart:String, p_sEnd:String):Array
[static] Returns pairs of start and end indices of a block in a source string.
StringUtil
  
getBlockByIndex(p_sStr:String, p_aPairs:Array, p_nIndex:Number, p_bNoSymbol:Boolean):String
[static] Returns a specific sub string of the source string.
StringUtil
  
getBlockRange(p_aPairs:Array, p_nIndex:Number):Array
[static] Returns The start and end indices for a substring, analyzed by findBlockIndex.
StringUtil
  
getBlocks(p_sStr:String, p_aPairs:Array, p_bWithSymbol:Boolean):Array
[static] Returns all blocks between start and end indices from a source string.
StringUtil
  
getTextBetween(p_sStr:String, p_sStart:String, p_sEnd:String):Array
[static] Returns all sub strings in a string between two given delimiter patterns.
StringUtil
  
indexTimes(p_sStr:String, p_sSubstr:String, p_nOccur:Number, p_nStart:Number):Number
[static] Returns the index of the N:th occurance of sub string.
StringUtil
  
replace(p_sStr:String, p_sOld:String, p_sNew:String):String
[static] Replaces a sub string with another in the target string.
StringUtil
Method detail
clear()method
public static function clear(p_sStr:String, p_aExpand:Array):String

Removes '\r' '\n' and replaces multiple spaces with a single space.

Parameters
p_sStr:String — The string to clean
 
p_aExpand:Array — Other strings you want to clear out

Returns
String
clearRepeat()method 
public static function clearRepeat(p_sStr:String, p_sRepeat:String, p_sReplace:String = ""):String

Clears the source string from multiple occurences of a pattern.

Ex: If you want to clear "ababab", you can use "ab" as a pattern.

Parameters
p_sStr:String — The pattern to clear out
 
p_sRepeat:String — Replace chars, default is a space.
 
p_sReplace:String (default = "")

Returns
String
findBlockIndex()method 
public static function findBlockIndex(p_sStr:String, p_sStart:String, p_sEnd:String):Array

Returns pairs of start and end indices of a block in a source string.

The target string is searched for blocks of text between a start and and an end delimiter string.
The start and end indices into the searched string, for each found block is stored in a two dimensional array.
All inices are returned as an array opf index pairs.

array struct:

array[0] = [Block_Start_String_Length, Block_End_String_Length]

array[1] = [Start_Index_1, End_Index_1]

array[x] = [Start_Index_x, End_Index_x]

param p_sStr The source string param p_sStart Block start with param p_sEnd Block end with return An array containtng all the start and end indices Parameters
p_sStr:String
 
p_sStart:String
 
p_sEnd:String

Returns
Array
getBlockByIndex()method 
public static function getBlockByIndex(p_sStr:String, p_aPairs:Array, p_nIndex:Number, p_bNoSymbol:Boolean):String

Returns a specific sub string of the source string.

Parameters
p_sStr:String — Source string
 
p_aPairs:Array — Index pairs created by findBlockIndex
 
p_nIndex:Number — Start index into the string of the block to search for
 
p_bNoSymbol:Boolean — Do not include start and end symbols

Returns
String — The searched sub string or an empty string if not found.
getBlockRange()method 
public static function getBlockRange(p_aPairs:Array, p_nIndex:Number):Array

Returns The start and end indices for a substring, analyzed by findBlockIndex.

Parameters
p_aPairs:Array — Index pairs created by findBlockIndex
 
p_nIndex:Number — Start index into the string of the block of interest

Returns
Array — The pair of start and end indices, [-1, -1] if not found.
getBlocks()method 
public static function getBlocks(p_sStr:String, p_aPairs:Array, p_bWithSymbol:Boolean):Array

Returns all blocks between start and end indices from a source string.

Given an array of index pairs, normally created by a call to findBlockIndex, all blocks between index pairs are extracted and stored in an array

Parameters
p_sStr:String — Source string
 
p_aPairs:Array — Index pairs created by findBlockIndex
 
p_bWithSymbol:Boolean — Include start and end symbols if set to true

Returns
Array — All blocks between the start and end indices
getTextBetween()method 
public static function getTextBetween(p_sStr:String, p_sStart:String, p_sEnd:String):Array

Returns all sub strings in a string between two given delimiter patterns.

The delimiters are not included in the results.

Parameters
p_sStr:String — The string we are going search for patterns.
 
p_sStart:String — The start delimiter
 
p_sEnd:String — The end delimiter

Returns
Array — An array of found sub strings. Empty if no matching patterns were found.
indexTimes()method 
public static function indexTimes(p_sStr:String, p_sSubstr:String, p_nOccur:Number, p_nStart:Number):Number

Returns the index of the N:th occurance of sub string.

Parameters
p_sStr:String — Source string
 
p_sSubstr:String — Sub string you want find
 
p_nOccur:Number — The occurance of the substriong to find
 
p_nStart:Number — Start index for the search

Returns
Number — Start index of the search sub string
replace()method 
public static function replace(p_sStr:String, p_sOld:String, p_sNew:String):String

Replaces a sub string with another in the target string.

Parameters
p_sStr:String — The string to modify ( target )
 
p_sOld:String — The old pattern to replace
 
p_sNew:String — The new pattern you want to replace with

Returns
String — The modified string.