package com.ericfeminella.utils
{
import mx.utils.StringUtil;
/**
*
* All static utility class which builds on mx.utils.StringUtil to add
* additional methods for replacing items in a specified String
*
* @see mx.utils.StringUtil
*
*/
public final class StringUtils extends AbstractStaticType
{
/**
*
* Replaces a specific section of a String with a new String Object
*
* @param The source String Object to perform the operation on
* @param The section of the source String to be replaced
* @param The String Object whjich will replace the section
*
*/
public static function replace(source:String, search:String, substitution:String) : String
{
var comp:Array = source.split(search);
var result:String = comp.join(substitution);
return result;
}
/**
*
* Replaces all instances of particular character(s) in a specific
* String with substitution character(s)
*
* @param The source String Object to perform the operation on
* @param The character in which all instances are to be replaced
* @param The character which will replace all instances
*
*/
public static function replaceCharacterInstances(source:String, character:String, substitution:String) : String
{
var result:String = "";
for (var i:int = 0; i < source.length; i++) {
if (source.charAt(i) == character)
{
result += substitution;
}
else
{
result += source.charAt(i)
}
}
return result;
}
/**
*
* Replaces all white space characters form the specified String
* Object and returns a new String without white space characters
*
* @param The string to trim whitespace
* @return The resulting trimmed String
*
*/
public static function trimWhiteSpace(source:String) : String
{
var pattern:RegExp = /[\s]+/g;
return source.replace(pattern, "");
}
/**
*
* Determines if the specified String contains alpha characters
*
* @param The string to evaluate
* @return true if the string contains alpha characters, otherwise false
*
*/
public static function containsAlpha(source:String) : Boolean
{
var pattern:RegExp = /[^a-zA-Z]/;
return source.search(pattern) != 0;
}
/**
*
* Determines if the specified String contains numeric characters
*
* @param The string to evaluate
* @return true if the string contains numeric characters, otherwise false
*
*/
public static function containsNumeric(source:String) : Boolean
{
var pattern:RegExp = /[^1-90-9]/;
return source.search(pattern) != 0;
}
/**
*
* Determines if the specified String contains alpha and / or numeric characters
*
* @param The string to evaluate
* @return true if the string contains alpha/numeric characters, otherwise false
*
*/
public static function containsAlphaNumeric(source:String) : Boolean
{
var pattern:RegExp = /[^a-zA-Z0-9]/;
return source.search(pattern) != 0;
}
/**
*
* Removes all xml / html tags and returns the a non-marked up String
*
* @param The string to remove html tags from
* @return the resulting non-marked up String
*
*/
public static function removeHTML(source:String) : String
{
var pattern:RegExp = /<[^>]*>/g;
return source.replace(pattern, "");
}
}
}