|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--org.apache.commons.lang.StringUtils
Common String manipulation routines.
Originally from Turbine and the GenerationJavaCore library.
| Constructor Summary | |
StringUtils()
StringUtils instances should NOT be constructed in standard programming. |
|
| Method Summary | |
static String |
capitalise(String str)
Capitalise a string. |
static String |
capitaliseAllWords(String str)
Capitalise all the words in a string. |
static String |
center(String str,
int size)
Center a string in a larger string of size n. |
static String |
center(String str,
int size,
String delim)
Center a string in a larger string of size n. |
static String |
chomp(String str)
Remove the last newline, and everything after it from a String. |
static String |
chomp(String str,
String sep)
Remove the last value of a supplied String, and everything after it from a String. |
static String |
chompLast(String str)
Remove a newline if and only if it is at the end of the supplied string. |
static String |
chompLast(String str,
String sep)
Remove a value if and only if the string ends with that value. |
static String |
chop(String str)
Remove the last character from a String. |
static String |
chopNewline(String str)
Remove \n from end of a String if it's there. |
static String |
clean(String str)
Removes control characters, including whitespace, from both ends of this string, handling null by returning an empty string. |
static String |
concatenate(Object[] array)
Concatenates elements of an array into a single string. |
static boolean |
containsOnly(String str,
char[] valid)
Checks if the String contains only certain chars. |
static int |
countMatches(String str,
String sub)
How many times is the substring in the larger string. |
static String |
defaultString(String str)
Return either the passed in String, or if it is null, then an empty String. |
static String |
defaultString(String str,
String defaultString)
Return either the passed in String, or if it is null, then a passed in default String. |
static String |
deleteSpaces(String str)
Deletes all 'space' characters from a String. |
static String |
deleteWhitespace(String str)
Deletes all whitespace from a String. |
static boolean |
equals(String str1,
String str2)
Compares two Strings, returning true if they are equal. |
static boolean |
equalsIgnoreCase(String str1,
String str2)
Compares two Strings, returning true if they are equal ignoring case. |
static String |
escape(String str)
Escapes any values it finds into their String form. |
static String |
getChomp(String str,
String sep)
Remove everything and return the last value of a supplied String, and everything after it from a String. |
static int |
getLevenshteinDistance(String s,
String t)
Find the Levenshtein distance between two strings. |
static String |
getNestedString(String str,
String tag)
Get the String that is nested in between two instances of the same String. |
static String |
getNestedString(String str,
String open,
String close)
Get the string that is nested in between two strings. |
static String |
getPrechomp(String str,
String sep)
Remove and return everything before the first value of a supplied String from another String. |
static int |
indexOfAny(String str,
String[] searchStrs)
Find the earliest index of any of a set of potential substrings. |
static boolean |
isAlpha(String str)
Checks if the string contains only unicode letters. |
static boolean |
isAlphanumeric(String str)
Checks if the string contains only unicode letters or digits. |
static boolean |
isAlphanumericSpace(String str)
Checks if the string contains only unicode letters, digits or space (' '). |
static boolean |
isAlphaSpace(String str)
Checks if the string contains only unicode letters and space (' '). |
static boolean |
isEmpty(String str)
Checks if a (trimmed) String is null or empty. |
static boolean |
isNotEmpty(String str)
Checks if a String is non null and is not empty (length > 0). |
static boolean |
isNumeric(String str)
Checks if the string contains only unicode digits. |
static boolean |
isNumericSpace(String str)
Checks if the string contains only unicode digits or space (' '). |
static String |
join(Iterator iterator,
String separator)
Joins the elements of the provided iterator into a single string containing the provided elements. |
static String |
join(Object[] array,
String separator)
Joins the elements of the provided array into a single string containing the provided list of elements. |
static int |
lastIndexOfAny(String str,
String[] searchStrs)
Find the latest index of any of a set of potential substrings. |
static String |
left(String str,
int len)
Gets the leftmost n characters of a string. |
static String |
leftPad(String str,
int size)
Left pad a String with spaces. |
static String |
leftPad(String str,
int size,
String delim)
Left pad a String with a specified string. |
static String |
lowerCase(String str)
Convert a String to lower case, null string returns null. |
static String |
mid(String str,
int pos,
int len)
Gets n characters from the middle of a string. |
static String |
overlayString(String text,
String overlay,
int start,
int end)
Overlay a part of a string with another string. |
static String |
prechomp(String str,
String sep)
Remove the first value of a supplied String, and everything before it from a String. |
static String |
repeat(String str,
int repeat)
Repeat a string n times to form a new string. |
static String |
replace(String text,
String repl,
String with)
Replace all occurances of a string within another string. |
static String |
replace(String text,
String repl,
String with,
int max)
Replace a string with another string inside a larger string, for the first max values of the search string. |
static String |
replaceOnce(String text,
String repl,
String with)
Replace a string with another string inside a larger string, once. |
static String |
reverse(String str)
Reverse a String, null string returns null. |
private static void |
reverseArray(Object[] array)
Reverses an array. |
static String |
reverseDelimitedString(String str,
String delimiter)
Reverses a string that is delimited by a specific character. |
static String |
right(String str,
int len)
Gets the rightmost n characters of a string. |
static String |
rightPad(String str,
int size)
Right pad a String with spaces. |
static String |
rightPad(String str,
int size,
String delim)
Right pad a String with a specified string. |
static String[] |
split(String str)
Splits the provided text into a list, using whitespace as the separator. |
static String[] |
split(String text,
String separator)
|
static String[] |
split(String str,
String separator,
int max)
Splits the provided text into a list, based on a given separator. |
static String |
strip(String str)
Remove whitespace from the front and back of a String. |
static String |
strip(String str,
String delim)
Remove a specified String from the front and back of a String. |
static String[] |
stripAll(String[] strs)
Strip whitespace from the front and back of every string in the array. |
static String[] |
stripAll(String[] strs,
String delimiter)
Strip the specified delimiter from the front and back of every String in the array. |
static String |
stripEnd(String str,
String strip)
Strip any of a supplied string from the end of a String.. |
static String |
stripStart(String str,
String strip)
Strip any of a supplied string from the start of a String. |
static String |
substring(String str,
int start)
Gets a substring of the specified string avoiding exceptions. |
static String |
substring(String str,
int start,
int end)
Gets a substring of the specified string avoiding exceptions. |
static String |
swapCase(String str)
Swaps the case of String. |
static String |
trim(String str)
Removes control characters, including whitespace, from both ends of this string, handling null by returning null. |
static String |
uncapitalise(String str)
Uncapitalise a string. |
static String |
upperCase(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, toString, wait, wait, wait |
| Constructor Detail |
public StringUtils()
StringUtils.trim(" foo ");.
This constructor is public to permit tools that require a JavaBean instance
to operate.
| Method Detail |
public static String clean(String str)
str - the string to check
null)String.trim()public static String trim(String str)
str - the string to check
null)String.trim()public static String deleteSpaces(String str)
str - String target to delete spaces from
NullPointerExceptionpublic static String deleteWhitespace(String str)
str - String target to delete whitespace from
NullPointerExceptionpublic static boolean isNotEmpty(String str)
str - the string to check
public static boolean isEmpty(String str)
str - the string to check
public static boolean equals(String str1,
String str2)
null
references are considered equal. Comparison is case sensitive.
str1 - the first stringstr2 - the second string
String.equals(Object)
public static boolean equalsIgnoreCase(String str1,
String str2)
null
references are considered equal. Comparison is case insensitive.
str1 - the first stringstr2 - the second string
String.equalsIgnoreCase(String)
public static int indexOfAny(String str,
String[] searchStrs)
str - the string to checksearchStrs - the strings to search for
NullPointerException - if any of searchStrs[i] is null
public static int lastIndexOfAny(String str,
String[] searchStrs)
str - the string to checksearchStrs - the strings to search for
NullPointerException - if any of searchStrs[i] is null
public static String substring(String str,
int start)
str - the string to get the substring fromstart - the position to start from, negative means
count back from the end of the string by this many characters
public static String substring(String str,
int start,
int end)
str - the string to get the substring fromstart - the position to start from, negative means
count back from the end of the string by this many charactersend - the position to end at (exclusive), negative means
count back from the end of the string by this many characters
public static String left(String str,
int len)
str - the string to get the leftmost characters fromlen - the length of the required string
IllegalArgumentException - if len is less than zero
public static String right(String str,
int len)
str - the string to get the rightmost characters fromlen - the length of the required string
IllegalArgumentException - if len is less than zero
public static String mid(String str,
int pos,
int len)
str - the string to get the characters frompos - the position to start fromlen - the length of the required string
IndexOutOfBoundsException - if pos is out of bounds
IllegalArgumentException - if len is less than zeropublic static String[] split(String str)
str - the string to parse
public static String[] split(String text,
String separator)
split(String, String, int)
public static String[] split(String str,
String separator,
int max)
This is useful for quickly splitting a string directly into
an array of tokens, instead of an enumeration of tokens (as
StringTokenizer does).
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.
public static String concatenate(Object[] array)
array - the array of values to concatenate.
public static String join(Object[] array,
String separator)
array - the array of values to join togetherseparator - the separator character to use
public static String join(Iterator iterator,
String separator)
iterator - the iterator of values to join togetherseparator - the separator character to use
public static String replaceOnce(String text,
String repl,
String with)
text - text to search and replace inrepl - String to search forwith - String to replace with
replace(String text, String repl, String with, int max)
public static String replace(String text,
String repl,
String with)
text - text to search and replace inrepl - String to search forwith - String to replace with
replace(String text, String repl, String with, int max)
public static String replace(String text,
String repl,
String with,
int max)
max values of the search string. A
null reference is passed to this method is a
no-op.
text - text to search and replace inrepl - String to search forwith - String to replace withmax - maximum number of values to replace, or
-1 if no maximum
NullPointerException - if repl is null
public static String overlayString(String text,
String overlay,
int start,
int end)
text - String to do overlaying inoverlay - String to overlaystart - int to start overlaying atend - int to stop overlaying before
NullPointerException - if text or overlay is null
public static String center(String str,
int size)
center(str, size, "")
str - String to centersize - int size of new String
NullPointerException - if str is null
public static String center(String str,
int size,
String delim)
str - String to centersize - int size of new Stringdelim - String to buffer the new String with
NullPointerException - if str or delim is null
ArithmeticException - if delim is the empty stringpublic static String chomp(String str)
str - String to chomp the newline from
NullPointerException - if str is null
public static String chomp(String str,
String sep)
str - String to chomp fromsep - String to chomp
NullPointerException - if str or sep is nullpublic static String chompLast(String str)
str - String to chomp from
NullPointerException - if str is null
public static String chompLast(String str,
String sep)
str - String to chomp fromsep - String to chomp
NullPointerException - if str or sep is null
public static String getChomp(String str,
String sep)
str - String to chomp fromsep - String to chomp
NullPointerException - if str or sep is null
public static String prechomp(String str,
String sep)
str - String to chomp fromsep - String to chomp
NullPointerException - if str or sep is null
public static String getPrechomp(String str,
String sep)
str - String to chomp fromsep - String to chomp
NullPointerException - if str or sep is nullpublic static String chop(String str)
str - String to chop last character from
NullPointerException - if str is nullpublic static String chopNewline(String str)
str - String to chop a newline from
NullPointerException - if str is nullpublic static String escape(String str)
str - String to escape values in
NullPointerException - if str is null
public static String repeat(String str,
int repeat)
str - String to repeatrepeat - int number of times to repeat
NegativeArraySizeException - if repeat < 0
NullPointerException - if str is null
public static String rightPad(String str,
int size)
str - String to repeatsize - int number of times to repeat
NullPointerException - if str is null
public static String rightPad(String str,
int size,
String delim)
str - String to pad outsize - int size to pad todelim - String to pad with
NullPointerException - if str or delim is null
ArithmeticException - if delim is the empty string
public static String leftPad(String str,
int size)
str - String to pad outsize - int size to pad to
NullPointerException - if str or delim is null
public static String leftPad(String str,
int size,
String delim)
str - String to pad outsize - int size to pad todelim - String to pad with
NullPointerException - if str or delim is null
ArithmeticException - if delim is the empty stringpublic static String strip(String str)
str - the string to remove whitespace from
public static String strip(String str,
String delim)
str - the string to remove a string fromdelim - the string to remove at start and end
public static String[] stripAll(String[] strs)
strs - the strings to remove whitespace from
public static String[] stripAll(String[] strs,
String delimiter)
strs - the strings to remove a string fromdelimiter - the string to remove at start and end
public static String stripEnd(String str,
String strip)
str - the string to remove characters fromstrip - the string to remove
public static String stripStart(String str,
String strip)
str - the string to remove characters fromstrip - the string to remove
public static String upperCase(String str)
str - the string to uppercase
public static String lowerCase(String str)
str - the string to lowercase
public static String uncapitalise(String str)
str - the string to uncapitalise
public static String capitalise(String str)
str - the string to capitalise
public static String swapCase(String str)
str - the string to swap the case of
public static String capitaliseAllWords(String str)
str - the string to capitalise
public static String getNestedString(String str,
String tag)
str - the string containing nested-stringtag - the string before and after nested-string
NullPointerException - if tag is null
public static String getNestedString(String str,
String open,
String close)
str - the string containing nested-stringopen - the string before nested-stringclose - the string after nested-string
NullPointerException - if open or close is null
public static int countMatches(String str,
String sub)
str - the string to checksub - the substring to count
NullPointerException - if sub is nullpublic static boolean isAlpha(String str)
str - the string to check
public static boolean isAlphaSpace(String str)
str - the string to check
public static boolean isAlphanumeric(String str)
str - the string to check
public static boolean isAlphanumericSpace(String str)
str - the string to check
public static boolean isNumeric(String str)
str - the string to check
public static boolean isNumericSpace(String str)
str - the string to check
public static String defaultString(String str)
str - the string to check
public static String defaultString(String str,
String defaultString)
str - the string to checkdefaultString - the default string to return is str is null
public static String reverse(String str)
str - the string to reverse
public static String reverseDelimitedString(String str,
String delimiter)
str - the string to reversedelimiter - the delimiter to use
private static void reverseArray(Object[] array)
array - the array to reverse
public static int getLevenshteinDistance(String s,
String t)
s - the first Stringt - the second String
NullPointerException - if s or t is null
public static boolean containsOnly(String str,
char[] valid)
str - the String to checkvalid - an array of valid chars
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||