org.apache.commons.lang
Class StringUtils

java.lang.Object
  |
  +--org.apache.commons.lang.StringUtils

public class StringUtils
extends java.lang.Object

Common String manipulation routines.

Originally from Turbine and the GenerationJavaCore library.

Version:
$Id: StringUtils.java,v 1.18.2.1 2002/11/23 01:06:56 bayard Exp $
Author:
Jon S. Stevens, Daniel Rall, Greg Coladonato, Henri Yandell, Ed Korthof, Stephen Colebourne,
Constructor Summary
StringUtils()
          StringUtils instances should NOT be constructed in standard programming.
 
Method Summary
static java.lang.String capitalise(java.lang.String str)
          Capitalise a string.
static java.lang.String capitaliseAllWords(java.lang.String str)
          Capitalise all the words in a string.
static java.lang.String center(java.lang.String str, int size)
          Center a string in a larger string of size n.
static java.lang.String center(java.lang.String str, int size, java.lang.String delim)
          Center a string in a larger string of size n.
static java.lang.String chomp(java.lang.String str)
          Remove the last newline, and everything after it from a String.
static java.lang.String chomp(java.lang.String str, java.lang.String sep)
          Remove the last value of a supplied String, and everything after it from a String.
static java.lang.String chompLast(java.lang.String str)
          Remove a newline if and only if it is at the end of the supplied string.
static java.lang.String chompLast(java.lang.String str, java.lang.String sep)
          Remove a value if and only if the string ends with that value.
static java.lang.String chop(java.lang.String str)
          Remove the last character from a String.
static java.lang.String chopNewline(java.lang.String str)
          Remove \n from end of a String if it's there.
static java.lang.String clean(java.lang.String str)
          Removes control characters, including whitespace, from both ends of this string, handling null by returning an empty string.
static java.lang.String concatenate(java.lang.Object[] array)
          Concatenates elements of an array into a single string.
static boolean containsOnly(java.lang.String str, char[] valid)
          Checks if the String contains only certain chars.
static int countMatches(java.lang.String str, java.lang.String sub)
          How many times is the substring in the larger string.
static java.lang.String defaultString(java.lang.String str)
          Return either the passed in String, or if it is null, then an empty String.
static java.lang.String defaultString(java.lang.String str, java.lang.String defaultString)
          Return either the passed in String, or if it is null, then a passed in default String.
static java.lang.String deleteSpaces(java.lang.String str)
          Deletes all 'space' characters from a String.
static java.lang.String deleteWhitespace(java.lang.String str)
          Deletes all whitespace from a String.
static boolean equals(java.lang.String str1, java.lang.String str2)
          Compares two Strings, returning true if they are equal.
static boolean equalsIgnoreCase(java.lang.String str1, java.lang.String str2)
          Compares two Strings, returning true if they are equal ignoring case.
static java.lang.String escape(java.lang.String str)
          Escapes any values it finds into their String form.
static java.lang.String getChomp(java.lang.String str, java.lang.String sep)
          Remove everything and return the last value of a supplied String, and everything after it from a String.
static int getLevenshteinDistance(java.lang.String s, java.lang.String t)
          Find the Levenshtein distance between two strings.
static java.lang.String getNestedString(java.lang.String str, java.lang.String tag)
          Get the String that is nested in between two instances of the same String.
static java.lang.String getNestedString(java.lang.String str, java.lang.String open, java.lang.String close)
          Get the string that is nested in between two strings.
static java.lang.String getPrechomp(java.lang.String str, java.lang.String sep)
          Remove and return everything before the first value of a supplied String from another String.
static int indexOfAny(java.lang.String str, java.lang.String[] searchStrs)
          Find the earliest index of any of a set of potential substrings.
static boolean isAlpha(java.lang.String str)
          Checks if the string contains only unicode letters.
static boolean isAlphanumeric(java.lang.String str)
          Checks if the string contains only unicode letters or digits.
static boolean isAlphanumericSpace(java.lang.String str)
          Checks if the string contains only unicode letters, digits or space (' ').
static boolean isAlphaSpace(java.lang.String str)
          Checks if the string contains only unicode letters and space (' ').
static boolean isEmpty(java.lang.String str)
          Checks if a (trimmed) String is null or empty.
static boolean isNotEmpty(java.lang.String str)
          Checks if a String is non null and is not empty (length > 0).
static boolean isNumeric(java.lang.String str)
          Checks if the string contains only unicode digits.
static boolean isNumericSpace(java.lang.String str)
          Checks if the string contains only unicode digits or space (' ').
static java.lang.String join(java.util.Iterator iterator, java.lang.String separator)
          Joins the elements of the provided iterator into a single string containing the provided elements.
static java.lang.String join(java.lang.Object[] array, java.lang.String separator)
          Joins the elements of the provided array into a single string containing the provided list of elements.
static int lastIndexOfAny(java.lang.String str, java.lang.String[] searchStrs)
          Find the latest index of any of a set of potential substrings.
static java.lang.String left(java.lang.String str, int len)
          Gets the leftmost n characters of a string.
static java.lang.String leftPad(java.lang.String str, int size)
          Left pad a String with spaces.
static java.lang.String leftPad(java.lang.String str, int size, java.lang.String delim)
          Left pad a String with a specified string.
static java.lang.String lowerCase(java.lang.String str)
          Convert a String to lower case, null string returns null.
static java.lang.String mid(java.lang.String str, int pos, int len)
          Gets n characters from the middle of a string.
static java.lang.String overlayString(java.lang.String text, java.lang.String overlay, int start, int end)
          Overlay a part of a string with another string.
static java.lang.String prechomp(java.lang.String str, java.lang.String sep)
          Remove the first value of a supplied String, and everything before it from a String.
static java.lang.String repeat(java.lang.String str, int repeat)
          Repeat a string n times to form a new string.
static java.lang.String replace(java.lang.String text, java.lang.String repl, java.lang.String with)
          Replace all occurances of a string within another string.
static java.lang.String replace(java.lang.String text, java.lang.String repl, java.lang.String with, int max)
          Replace a string with another string inside a larger string, for the first max values of the search string.
static java.lang.String replaceOnce(java.lang.String text, java.lang.String repl, java.lang.String with)
          Replace a string with another string inside a larger string, once.
static java.lang.String reverse(java.lang.String str)
          Reverse a String, null string returns null.
private static void reverseArray(java.lang.Object[] array)
          Reverses an array.
static java.lang.String reverseDelimitedString(java.lang.String str, java.lang.String delimiter)
          Reverses a string that is delimited by a specific character.
static java.lang.String right(java.lang.String str, int len)
          Gets the rightmost n characters of a string.
static java.lang.String rightPad(java.lang.String str, int size)
          Right pad a String with spaces.
static java.lang.String rightPad(java.lang.String str, int size, java.lang.String delim)
          Right pad a String with a specified string.
static java.lang.String[] split(java.lang.String str)
          Splits the provided text into a list, using whitespace as the separator.
static java.lang.String[] split(java.lang.String text, java.lang.String separator)
           
static java.lang.String[] split(java.lang.String str, java.lang.String separator, int max)
          Splits the provided text into a list, based on a given separator.
static java.lang.String strip(java.lang.String str)
          Remove whitespace from the front and back of a String.
static java.lang.String strip(java.lang.String str, java.lang.String delim)
          Remove a specified String from the front and back of a String.
static java.lang.String[] stripAll(java.lang.String[] strs)
          Strip whitespace from the front and back of every string in the array.
static java.lang.String[] stripAll(java.lang.String[] strs, java.lang.String delimiter)
          Strip the specified delimiter from the front and back of every String in the array.
static java.lang.String stripEnd(java.lang.String str, java.lang.String strip)
          Strip any of a supplied string from the end of a String..
static java.lang.String stripStart(java.lang.String str, java.lang.String strip)
          Strip any of a supplied string from the start of a String.
static java.lang.String substring(java.lang.String str, int start)
          Gets a substring of the specified string avoiding exceptions.
static java.lang.String substring(java.lang.String str, int start, int end)
          Gets a substring of the specified string avoiding exceptions.
static java.lang.String swapCase(java.lang.String str)
          Swaps the case of String.
static java.lang.String trim(java.lang.String str)
          Removes control characters, including whitespace, from both ends of this string, handling null by returning null.
static java.lang.String uncapitalise(java.lang.String str)
          Uncapitalise a string.
static java.lang.String upperCase(java.lang.String str)
          Convert a String to upper case, null string returns null.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Constructor Detail

StringUtils

public StringUtils()
StringUtils instances should NOT be constructed in standard programming. Instead, the class should be used as StringUtils.trim(" foo ");. This constructor is public to permit tools that require a JavaBean instance to operate.
Method Detail

clean

public static java.lang.String clean(java.lang.String str)
Removes control characters, including whitespace, from both ends of this string, handling null by returning an empty string.
Parameters:
str - the string to check
Returns:
the trimmed text (never null)
See Also:
String.trim()

trim

public static java.lang.String trim(java.lang.String str)
Removes control characters, including whitespace, from both ends of this string, handling null by returning null.
Parameters:
str - the string to check
Returns:
the trimmed text (or null)
See Also:
String.trim()

deleteSpaces

public static java.lang.String deleteSpaces(java.lang.String str)
Deletes all 'space' characters from a String. Spaces are defined as {' ', '\t', '\r', '\n', '\b'} in line with the deprecated Character.isSpace
Parameters:
str - String target to delete spaces from
Returns:
the text without spaces
Throws:
NullPointerException -  

deleteWhitespace

public static java.lang.String deleteWhitespace(java.lang.String str)
Deletes all whitespace from a String. Whitespace is defined by Character.isWhitespace
Parameters:
str - String target to delete whitespace from
Returns:
the text without whitespace
Throws:
NullPointerException -  

isNotEmpty

public static boolean isNotEmpty(java.lang.String str)
Checks if a String is non null and is not empty (length > 0).
Parameters:
str - the string to check
Returns:
true if the String is non-null, and not length zero

isEmpty

public static boolean isEmpty(java.lang.String str)
Checks if a (trimmed) String is null or empty.
Parameters:
str - the string to check
Returns:
true if the String is null, or length zero once trimmed

equals

public static boolean equals(java.lang.String str1,
                             java.lang.String str2)
Compares two Strings, returning true if they are equal. Nulls are handled without exceptions. Two null references are considered equal. Comparison is case sensitive.
Parameters:
str1 - the first string
str2 - the second string
Returns:
true if the Strings are equal, case sensitive, or both null
See Also:
String.equals(Object)

equalsIgnoreCase

public static boolean equalsIgnoreCase(java.lang.String str1,
                                       java.lang.String str2)
Compares two Strings, returning true if they are equal ignoring case. Nulls are handled without exceptions. Two null references are considered equal. Comparison is case insensitive.
Parameters:
str1 - the first string
str2 - the second string
Returns:
true if the Strings are equal, case insensitive, or both null
See Also:
String.equalsIgnoreCase(String)

indexOfAny

public static int indexOfAny(java.lang.String str,
                             java.lang.String[] searchStrs)
Find the earliest index of any of a set of potential substrings. Null string will return -1.
Parameters:
str - the string to check
searchStrs - the strings to search for
Returns:
the earliest index of any of the strings
Throws:
NullPointerException - if any of searchStrs[i] is null

lastIndexOfAny

public static int lastIndexOfAny(java.lang.String str,
                                 java.lang.String[] searchStrs)
Find the latest index of any of a set of potential substrings. Null string will return -1.
Parameters:
str - the string to check
searchStrs - the strings to search for
Returns:
the last index of any of the strings
Throws:
NullPointerException - if any of searchStrs[i] is null

substring

public static java.lang.String substring(java.lang.String str,
                                         int start)
Gets a substring of the specified string avoiding exceptions. A negative start position can be used to start n characters from the end of the string.
Parameters:
str - the string to get the substring from
start - the position to start from, negative means count back from the end of the string by this many characters
Returns:
substring from start position

substring

public static java.lang.String substring(java.lang.String str,
                                         int start,
                                         int end)
Gets a substring of the specified string avoiding exceptions. A negative start position can be used to start/end n characters from the end of the string.
Parameters:
str - the string to get the substring from
start - the position to start from, negative means count back from the end of the string by this many characters
end - the position to end at (exclusive), negative means count back from the end of the string by this many characters
Returns:
substring from start position to end positon

left

public static java.lang.String left(java.lang.String str,
                                    int len)
Gets the leftmost n characters of a string. If n characters are not available, or the string is null, the string will be returned without an exception.
Parameters:
str - the string to get the leftmost characters from
len - the length of the required string
Returns:
the leftmost characters
Throws:
java.lang.IllegalArgumentException - if len is less than zero

right

public static java.lang.String right(java.lang.String str,
                                     int len)
Gets the rightmost n characters of a string. If n characters are not available, or the string is null, the string will be returned without an exception.
Parameters:
str - the string to get the rightmost characters from
len - the length of the required string
Returns:
the leftmost characters
Throws:
java.lang.IllegalArgumentException - if len is less than zero

mid

public static java.lang.String mid(java.lang.String str,
                                   int pos,
                                   int len)
Gets n characters from the middle of a string. If n characters are not available, the remainder of the string will be returned without an exception. If the string is null, null will be returned.
Parameters:
str - the string to get the characters from
pos - the position to start from
len - the length of the required string
Returns:
the leftmost characters
Throws:
IndexOutOfBoundsException - if pos is out of bounds
java.lang.IllegalArgumentException - if len is less than zero

split

public static java.lang.String[] split(java.lang.String str)
Splits the provided text into a list, using whitespace as the separator. The separator is not included in the returned String array.
Parameters:
str - the string to parse
Returns:
an array of parsed Strings

split

public static java.lang.String[] split(java.lang.String text,
                                       java.lang.String separator)
See Also:
split(String, String, int)

split

public static java.lang.String[] split(java.lang.String str,
                                       java.lang.String separator,
                                       int max)
Splits the provided text into a list, based on a given separator. The separator is not included in the returned String array. The maximum number of splits to perfom can be controlled. A null separator will cause parsing to be on whitespace.

This is useful for quickly splitting a string directly into an array of tokens, instead of an enumeration of tokens (as StringTokenizer does).

Parameters:
str - The string to parse.
separator - Characters used as the delimiters. If null, splits on whitespace.
max - The maximum number of elements to include in the list. A zero or negative value implies no limit.
Returns:
an array of parsed Strings

concatenate

public static java.lang.String concatenate(java.lang.Object[] array)
Concatenates elements of an array into a single string. The difference from join is that concatenate has no delimiter.
Parameters:
array - the array of values to concatenate.
Returns:
the concatenated string.

join

public static java.lang.String join(java.lang.Object[] array,
                                    java.lang.String separator)
Joins the elements of the provided array into a single string containing the provided list of elements. No delimiter is added before or after the list. A null separator is the same as a blank String.
Parameters:
array - the array of values to join together
separator - the separator character to use
Returns:
the joined String

join

public static java.lang.String join(java.util.Iterator iterator,
                                    java.lang.String separator)
Joins the elements of the provided iterator into a single string containing the provided elements. No delimiter is added before or after the list. A null separator is the same as a blank String.
Parameters:
iterator - the iterator of values to join together
separator - the separator character to use
Returns:
the joined String

replaceOnce

public static java.lang.String replaceOnce(java.lang.String text,
                                           java.lang.String repl,
                                           java.lang.String with)
Replace a string with another string inside a larger string, once.
Parameters:
text - text to search and replace in
repl - String to search for
with - String to replace with
Returns:
the text with any replacements processed
See Also:
replace(String text, String repl, String with, int max)

replace

public static java.lang.String replace(java.lang.String text,
                                       java.lang.String repl,
                                       java.lang.String with)
Replace all occurances of a string within another string.
Parameters:
text - text to search and replace in
repl - String to search for
with - String to replace with
Returns:
the text with any replacements processed
See Also:
replace(String text, String repl, String with, int max)

replace

public static java.lang.String replace(java.lang.String text,
                                       java.lang.String repl,
                                       java.lang.String with,
                                       int max)
Replace a string with another string inside a larger string, for the first max values of the search string. A null reference is passed to this method is a no-op.
Parameters:
text - text to search and replace in
repl - String to search for
with - String to replace with
max - maximum number of values to replace, or -1 if no maximum
Returns:
the text with any replacements processed
Throws:
NullPointerException - if repl is null

overlayString

public static java.lang.String overlayString(java.lang.String text,
                                             java.lang.String overlay,
                                             int start,
                                             int end)
Overlay a part of a string with another string.
Parameters:
text - String to do overlaying in
overlay - String to overlay
start - int to start overlaying at
end - int to stop overlaying before
Returns:
String with overlayed text
Throws:
NullPointerException - if text or overlay is null

center

public static java.lang.String center(java.lang.String str,
                                      int size)
Center a string in a larger string of size n. Uses spaces as the value to buffer the string with. Equivalent to center(str, size, "")
Parameters:
str - String to center
size - int size of new String
Returns:
String containing centered String
Throws:
NullPointerException - if str is null

center

public static java.lang.String center(java.lang.String str,
                                      int size,
                                      java.lang.String delim)
Center a string in a larger string of size n. Uses a supplied String as the value to buffer the string with..
Parameters:
str - String to center
size - int size of new String
delim - String to buffer the new String with
Returns:
String containing centered String
Throws:
NullPointerException - if str or delim is null
ArithmeticException - if delim is the empty string

chomp

public static java.lang.String chomp(java.lang.String str)
Remove the last newline, and everything after it from a String.
Parameters:
str - String to chomp the newline from
Returns:
String without chomped newline
Throws:
NullPointerException - if str is null

chomp

public static java.lang.String chomp(java.lang.String str,
                                     java.lang.String sep)
Remove the last value of a supplied String, and everything after it from a String.
Parameters:
str - String to chomp from
sep - String to chomp
Returns:
String without chomped ending
Throws:
NullPointerException - if str or sep is null

chompLast

public static java.lang.String chompLast(java.lang.String str)
Remove a newline if and only if it is at the end of the supplied string.
Parameters:
str - String to chomp from
Returns:
String without chomped ending
Throws:
NullPointerException - if str is null

chompLast

public static java.lang.String chompLast(java.lang.String str,
                                         java.lang.String sep)
Remove a value if and only if the string ends with that value.
Parameters:
str - String to chomp from
sep - String to chomp
Returns:
String without chomped ending
Throws:
NullPointerException - if str or sep is null

getChomp

public static java.lang.String getChomp(java.lang.String str,
                                        java.lang.String sep)
Remove everything and return the last value of a supplied String, and everything after it from a String.
Parameters:
str - String to chomp from
sep - String to chomp
Returns:
String chomped
Throws:
NullPointerException - if str or sep is null

prechomp

public static java.lang.String prechomp(java.lang.String str,
                                        java.lang.String sep)
Remove the first value of a supplied String, and everything before it from a String.
Parameters:
str - String to chomp from
sep - String to chomp
Returns:
String without chomped beginning
Throws:
NullPointerException - if str or sep is null

getPrechomp

public static java.lang.String getPrechomp(java.lang.String str,
                                           java.lang.String sep)
Remove and return everything before the first value of a supplied String from another String.
Parameters:
str - String to chomp from
sep - String to chomp
Returns:
String prechomped
Throws:
NullPointerException - if str or sep is null

chop

public static java.lang.String chop(java.lang.String str)
Remove the last character from a String. If the String ends in \r\n, then remove both of them.
Parameters:
str - String to chop last character from
Returns:
String without last character
Throws:
NullPointerException - if str is null

chopNewline

public static java.lang.String chopNewline(java.lang.String str)
Remove \n from end of a String if it's there. If a \r precedes it, then remove that too.
Parameters:
str - String to chop a newline from
Returns:
String without newline
Throws:
NullPointerException - if str is null

escape

public static java.lang.String escape(java.lang.String str)
Escapes any values it finds into their String form. So a tab becomes the characters '\\' and 't'.
Parameters:
str - String to escape values in
Returns:
String with escaped values
Throws:
NullPointerException - if str is null

repeat

public static java.lang.String repeat(java.lang.String str,
                                      int repeat)
Repeat a string n times to form a new string.
Parameters:
str - String to repeat
repeat - int number of times to repeat
Returns:
String with repeated string
Throws:
NegativeArraySizeException - if repeat < 0
NullPointerException - if str is null

rightPad

public static java.lang.String rightPad(java.lang.String str,
                                        int size)
Right pad a String with spaces. Pad to a size of n.
Parameters:
str - String to repeat
size - int number of times to repeat
Returns:
right padded String
Throws:
NullPointerException - if str is null

rightPad

public static java.lang.String rightPad(java.lang.String str,
                                        int size,
                                        java.lang.String delim)
Right pad a String with a specified string. Pad to a size of n.
Parameters:
str - String to pad out
size - int size to pad to
delim - String to pad with
Returns:
right padded String
Throws:
NullPointerException - if str or delim is null
ArithmeticException - if delim is the empty string

leftPad

public static java.lang.String leftPad(java.lang.String str,
                                       int size)
Left pad a String with spaces. Pad to a size of n.
Parameters:
str - String to pad out
size - int size to pad to
Returns:
left padded String
Throws:
NullPointerException - if str or delim is null

leftPad

public static java.lang.String leftPad(java.lang.String str,
                                       int size,
                                       java.lang.String delim)
Left pad a String with a specified string. Pad to a size of n.
Parameters:
str - String to pad out
size - int size to pad to
delim - String to pad with
Returns:
left padded String
Throws:
NullPointerException - if str or delim is null
ArithmeticException - if delim is the empty string

strip

public static java.lang.String strip(java.lang.String str)
Remove whitespace from the front and back of a String.
Parameters:
str - the string to remove whitespace from
Returns:
the stripped string

strip

public static java.lang.String strip(java.lang.String str,
                                     java.lang.String delim)
Remove a specified String from the front and back of a String. If Whitespace is wanted to be removed, used the strip(String) method.
Parameters:
str - the string to remove a string from
delim - the string to remove at start and end
Returns:
the stripped string

stripAll

public static java.lang.String[] stripAll(java.lang.String[] strs)
Strip whitespace from the front and back of every string in the array.
Parameters:
strs - the strings to remove whitespace from
Returns:
the stripped strings

stripAll

public static java.lang.String[] stripAll(java.lang.String[] strs,
                                          java.lang.String delimiter)
Strip the specified delimiter from the front and back of every String in the array.
Parameters:
strs - the strings to remove a string from
delimiter - the string to remove at start and end
Returns:
the stripped strings

stripEnd

public static java.lang.String stripEnd(java.lang.String str,
                                        java.lang.String strip)
Strip any of a supplied string from the end of a String.. If the strip string is null, whitespace is stripped.
Parameters:
str - the string to remove characters from
strip - the string to remove
Returns:
the stripped string

stripStart

public static java.lang.String stripStart(java.lang.String str,
                                          java.lang.String strip)
Strip any of a supplied string from the start of a String. If the strip string is null, whitespace is stripped.
Parameters:
str - the string to remove characters from
strip - the string to remove
Returns:
the stripped string

upperCase

public static java.lang.String upperCase(java.lang.String str)
Convert a String to upper case, null string returns null.
Parameters:
str - the string to uppercase
Returns:
the upper cased string

lowerCase

public static java.lang.String lowerCase(java.lang.String str)
Convert a String to lower case, null string returns null.
Parameters:
str - the string to lowercase
Returns:
the lower cased string

uncapitalise

public static java.lang.String uncapitalise(java.lang.String str)
Uncapitalise a string. That is, convert the first character into lower-case. Null is returned as null.
Parameters:
str - the string to uncapitalise
Returns:
uncapitalised string

capitalise

public static java.lang.String capitalise(java.lang.String str)
Capitalise a string. That is, convert the first character into title-case. Null is returned as null.
Parameters:
str - the string to capitalise
Returns:
capitalised string

swapCase

public static java.lang.String swapCase(java.lang.String str)
Swaps the case of String. Properly looks after making sure the start of words are Titlecase and not Uppercase. Null is returned as null.
Parameters:
str - the string to swap the case of
Returns:
the modified string

capitaliseAllWords

public static java.lang.String capitaliseAllWords(java.lang.String str)
Capitalise all the words in a string. Uses Character.isWhitespace as a separator between words. Null will return null.
Parameters:
str - the string to capitalise
Returns:
capitalised string

getNestedString

public static java.lang.String getNestedString(java.lang.String str,
                                               java.lang.String tag)
Get the String that is nested in between two instances of the same String. If str is null, will return null
Parameters:
str - the string containing nested-string
tag - the string before and after nested-string
Returns:
the string that was nested, or null
Throws:
NullPointerException - if tag is null

getNestedString

public static java.lang.String getNestedString(java.lang.String str,
                                               java.lang.String open,
                                               java.lang.String close)
Get the string that is nested in between two strings.
Parameters:
str - the string containing nested-string
open - the string before nested-string
close - the string after nested-string
Returns:
the string that was nested, or null
Throws:
NullPointerException - if open or close is null

countMatches

public static int countMatches(java.lang.String str,
                               java.lang.String sub)
How many times is the substring in the larger string. Null returns 0.
Parameters:
str - the string to check
sub - the substring to count
Returns:
the number of occurances, 0 if the string is null
Throws:
NullPointerException - if sub is null

isAlpha

public static boolean isAlpha(java.lang.String str)
Checks if the string contains only unicode letters. Null will return false. The empty string will return true.
Parameters:
str - the string to check
Returns:
true if only contains letters, and is non-null

isAlphaSpace

public static boolean isAlphaSpace(java.lang.String str)
Checks if the string contains only unicode letters and space (' '). Null will return false. The empty string will return true.
Parameters:
str - the string to check
Returns:
true if only contains letters and space, and is non-null

isAlphanumeric

public static boolean isAlphanumeric(java.lang.String str)
Checks if the string contains only unicode letters or digits. Null will return false. The empty string will return true.
Parameters:
str - the string to check
Returns:
true if only contains letters or digits, and is non-null

isAlphanumericSpace

public static boolean isAlphanumericSpace(java.lang.String str)
Checks if the string contains only unicode letters, digits or space (' '). Null will return false. The empty string will return true.
Parameters:
str - the string to check
Returns:
true if only contains letters, digits or space, and is non-null

isNumeric

public static boolean isNumeric(java.lang.String str)
Checks if the string contains only unicode digits. Null will return false. The empty string will return true.
Parameters:
str - the string to check
Returns:
true if only contains digits, and is non-null

isNumericSpace

public static boolean isNumericSpace(java.lang.String str)
Checks if the string contains only unicode digits or space (' '). Null will return false. The empty string will return true.
Parameters:
str - the string to check
Returns:
true if only contains digits or space, and is non-null

defaultString

public static java.lang.String defaultString(java.lang.String str)
Return either the passed in String, or if it is null, then an empty String.
Parameters:
str - the string to check
Returns:
the passed in string, or blank if it was null

defaultString

public static java.lang.String defaultString(java.lang.String str,
                                             java.lang.String defaultString)
Return either the passed in String, or if it is null, then a passed in default String.
Parameters:
str - the string to check
defaultString - the default string to return is str is null
Returns:
the passed in string, or the default if it was null

reverse

public static java.lang.String reverse(java.lang.String str)
Reverse a String, null string returns null.
Parameters:
str - the string to reverse
Returns:
the reversed string

reverseDelimitedString

public static java.lang.String reverseDelimitedString(java.lang.String str,
                                                      java.lang.String delimiter)
Reverses a string that is delimited by a specific character. The strings between the delimiters are not reversed. Thus java.lang.String becomes String.lang.java (if the delimiter is '.').
Parameters:
str - the string to reverse
delimiter - the delimiter to use
Returns:
the reversed string

reverseArray

private static void reverseArray(java.lang.Object[] array)
Reverses an array. TAKEN FROM CollectionsUtils.
Parameters:
array - the array to reverse

getLevenshteinDistance

public static int getLevenshteinDistance(java.lang.String s,
                                         java.lang.String t)
Find the Levenshtein distance between two strings. This is the number of changes needed to change one string into another. Where each change is a single character modification. This implemmentation of the levenshtein distance algorithm is from http://www.merriampark.com/ld.htm
Parameters:
s - the first String
t - the second String
Returns:
int result distance
Throws:
NullPointerException - if s or t is null

containsOnly

public static boolean containsOnly(java.lang.String str,
                                   char[] valid)
Checks if the String contains only certain chars.
Parameters:
str - the String to check
valid - an array of valid chars
Returns:
true if it only contains valid chars and is non-null


Copyright (c) 2001-2002 - Apache Software Foundation