com.anthonyeden.lib.util
Class TextUtilities

java.lang.Object
  extended bycom.anthonyeden.lib.util.TextUtilities

public final class TextUtilities
extends java.lang.Object

Useful text manipulation methods.

Author:
Anthony Eden

Field Summary
static java.lang.String DEFAULT_DELIMITER
          Default delimiter.
 
Method Summary
static java.lang.String asciiToNative(java.lang.String theString)
          Convert a unicode escaped String into its native form.
static java.lang.String capitalize(java.lang.String text)
          Capitalize the first letter of the given text.
static java.util.List chompString(java.lang.String text)
          Split the String on newlines.
static boolean hasNonAlphaNumericCharacters(java.lang.String str)
          Returns true if the given String contains at least one non alpha- numeric character.
static boolean hasNonAlphaNumericCharacters(java.lang.String str, char[] ignore)
          Returns true if the given String contains at least one non alpha- numeric character.
static boolean isAscii(char c)
          Return true if the character is an ASCII character.
static boolean isExtendedAscii(char c)
          Return true if the character is an extended ASCII character.
static java.lang.String join(java.util.Collection data)
          Join the given Collection using the DEFAULT_DELIMITER.
static java.lang.String join(java.util.Collection data, java.lang.String delimiter)
          Join the given Collection using the given delimiter.
static java.lang.String join(java.lang.Object[] data)
          Join the given Object array using the DEFAULT_DELIMITER.
static java.lang.String join(java.lang.Object[] data, java.lang.String delimiter)
          Join the given Object array using the given delimiter.
static java.lang.String nativeToAscii(java.lang.String text)
          Convert the given String of characters from their native values to a Unicode escaped String.
static java.lang.String remove(java.lang.String src, char[] removeChars)
          Remove all instances of the given characters from the given String.
static java.lang.String removeWhitespace(java.lang.String src)
          Remove all whitespace from the given String.
static java.lang.String replace(java.lang.String str, java.lang.String searchString, java.lang.String replacementString)
          Replace all instances of a String within another String.
static java.util.List splitString(java.lang.String text, java.lang.String separator)
          Split the given text using the given separator.
static java.util.List splitString(java.lang.String text, java.lang.String separator, boolean removeWhitespace)
          Split the given text using the given separator.
static java.util.List splitStringOnWhitespace(java.lang.String text)
          Split the given String on whitespace characters.
static java.lang.String stripNonAlphaNumericCharacters(java.lang.String str)
          String all non alpha-numeric characters from the given String.
static java.lang.String stripNonAlphaNumericCharacters(java.lang.String str, char[] ignore)
          Strip all non alpha-numeric characters from the given String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DELIMITER

public static final java.lang.String DEFAULT_DELIMITER
Default delimiter.

See Also:
Constant Field Values
Method Detail

replace

public static java.lang.String replace(java.lang.String str,
                                       java.lang.String searchString,
                                       java.lang.String replacementString)
Replace all instances of a String within another String.

Parameters:
str - The complete String
searchString - The search String
replacementString - The replacement String

remove

public static java.lang.String remove(java.lang.String src,
                                      char[] removeChars)
Remove all instances of the given characters from the given String.

Parameters:
src - The source String
removeChars - The characters to remove
Returns:
The result String

removeWhitespace

public static java.lang.String removeWhitespace(java.lang.String src)
Remove all whitespace from the given String.

Parameters:
src - The source String
Returns:
The resulting String

hasNonAlphaNumericCharacters

public static boolean hasNonAlphaNumericCharacters(java.lang.String str)
Returns true if the given String contains at least one non alpha- numeric character.

Parameters:
str - The String
Returns:
True if one or more alpha-numeric characters are found

hasNonAlphaNumericCharacters

public static boolean hasNonAlphaNumericCharacters(java.lang.String str,
                                                   char[] ignore)
Returns true if the given String contains at least one non alpha- numeric character. Characters in the ignore array are not checked.

Parameters:
str - The String
ignore - An array of characters to ignore
Returns:
True if one or more alpha-numeric characters are found

stripNonAlphaNumericCharacters

public static java.lang.String stripNonAlphaNumericCharacters(java.lang.String str)
String all non alpha-numeric characters from the given String.

Parameters:
str - The String
Returns:
The new String

stripNonAlphaNumericCharacters

public static java.lang.String stripNonAlphaNumericCharacters(java.lang.String str,
                                                              char[] ignore)
Strip all non alpha-numeric characters from the given String. Characters contained in the ignore array will be left within the String.

Parameters:
str - The String
ignore - An array of characters to ignore
Returns:
The new String

capitalize

public static java.lang.String capitalize(java.lang.String text)
Capitalize the first letter of the given text.

Parameters:
text - The original text
Returns:
The capitalized text

splitString

public static java.util.List splitString(java.lang.String text,
                                         java.lang.String separator)
Split the given text using the given separator.

Parameters:
text - The original text
separator - The separator
Returns:
The result List of String objects

splitString

public static java.util.List splitString(java.lang.String text,
                                         java.lang.String separator,
                                         boolean removeWhitespace)
Split the given text using the given separator.

Parameters:
text - The original text
separator - The separator
Returns:
The result List of String objects

splitStringOnWhitespace

public static java.util.List splitStringOnWhitespace(java.lang.String text)
Split the given String on whitespace characters.

Parameters:
text - The source String
Returns:
A List of String objects

chompString

public static java.util.List chompString(java.lang.String text)
Split the String on newlines.

Parameters:
text - The source text
Returns:
A List of String objects

join

public static java.lang.String join(java.lang.Object[] data)
Join the given Object array using the DEFAULT_DELIMITER.

Parameters:
data - The data array
Returns:
The resulting String

join

public static java.lang.String join(java.lang.Object[] data,
                                    java.lang.String delimiter)
Join the given Object array using the given delimiter. The toString() method on each Object will be invoked to retrieve a String representation of the Object.

Parameters:
data - The data array
delimiter - The delimiter String
Returns:
The resulting String

join

public static java.lang.String join(java.util.Collection data)
Join the given Collection using the DEFAULT_DELIMITER.

Parameters:
data - The collection
Returns:
The resulting String

join

public static java.lang.String join(java.util.Collection data,
                                    java.lang.String delimiter)
Join the given Collection using the given delimiter. The toString() method on each Object will be invoked to retrieve a String representation of the Object.

Parameters:
data - The collection
delimiter - The delimiter String
Returns:
The resulting String

isAscii

public static boolean isAscii(char c)
Return true if the character is an ASCII character.

Parameters:
c - The character
Returns:
True if character is ASCII

isExtendedAscii

public static boolean isExtendedAscii(char c)
Return true if the character is an extended ASCII character.

Parameters:
c - The character
Returns:
True if character is extended ASCII

nativeToAscii

public static java.lang.String nativeToAscii(java.lang.String text)
Convert the given String of characters from their native values to a Unicode escaped String.

Parameters:
text - The original text
Returns:
The unicode encoded text

asciiToNative

public static java.lang.String asciiToNative(java.lang.String theString)
Convert a unicode escaped String into its native form.

Parameters:
theString - Unicode escaped String
Returns:
The native String


Copyright (c) 2000-2003 Anthony Eden. All Rights Reserved.