|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | 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 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 |
|
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 java.lang.String clean(java.lang.String str)
str
- the string to checknull
)String.trim()
public static java.lang.String trim(java.lang.String str)
str
- the string to checknull
)String.trim()
public static java.lang.String deleteSpaces(java.lang.String str)
str
- String target to delete spaces fromNullPointerException
- public static java.lang.String deleteWhitespace(java.lang.String str)
str
- String target to delete whitespace fromNullPointerException
- public static boolean isNotEmpty(java.lang.String str)
str
- the string to checkpublic static boolean isEmpty(java.lang.String str)
str
- the string to checkpublic static boolean equals(java.lang.String str1, java.lang.String str2)
null
references are considered equal. Comparison is case sensitive.str1
- the first stringstr2
- the second stringString.equals(Object)
public static boolean equalsIgnoreCase(java.lang.String str1, java.lang.String str2)
null
references are considered equal. Comparison is case insensitive.str1
- the first stringstr2
- the second stringString.equalsIgnoreCase(String)
public static int indexOfAny(java.lang.String str, java.lang.String[] searchStrs)
str
- the string to checksearchStrs
- the strings to search forNullPointerException
- if any of searchStrs[i] is nullpublic static int lastIndexOfAny(java.lang.String str, java.lang.String[] searchStrs)
str
- the string to checksearchStrs
- the strings to search forNullPointerException
- if any of searchStrs[i] is nullpublic static java.lang.String substring(java.lang.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 characterspublic static java.lang.String substring(java.lang.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 characterspublic static java.lang.String left(java.lang.String str, int len)
str
- the string to get the leftmost characters fromlen
- the length of the required stringjava.lang.IllegalArgumentException
- if len is less than zeropublic static java.lang.String right(java.lang.String str, int len)
str
- the string to get the rightmost characters fromlen
- the length of the required stringjava.lang.IllegalArgumentException
- if len is less than zeropublic static java.lang.String mid(java.lang.String str, int pos, int len)
str
- the string to get the characters frompos
- the position to start fromlen
- the length of the required stringIndexOutOfBoundsException
- if pos is out of boundsjava.lang.IllegalArgumentException
- if len is less than zeropublic static java.lang.String[] split(java.lang.String str)
str
- the string to parsepublic static java.lang.String[] split(java.lang.String text, java.lang.String separator)
split(String, String, int)
public static java.lang.String[] split(java.lang.String str, java.lang.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 java.lang.String concatenate(java.lang.Object[] array)
array
- the array of values to concatenate.public static java.lang.String join(java.lang.Object[] array, java.lang.String separator)
array
- the array of values to join togetherseparator
- the separator character to usepublic static java.lang.String join(java.util.Iterator iterator, java.lang.String separator)
iterator
- the iterator of values to join togetherseparator
- the separator character to usepublic static java.lang.String replaceOnce(java.lang.String text, java.lang.String repl, java.lang.String with)
text
- text to search and replace inrepl
- String to search forwith
- String to replace withreplace(String text, String repl, String with, int max)
public static java.lang.String replace(java.lang.String text, java.lang.String repl, java.lang.String with)
text
- text to search and replace inrepl
- String to search forwith
- String to replace withreplace(String text, String repl, String with, int max)
public static java.lang.String replace(java.lang.String text, java.lang.String repl, java.lang.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 maximumNullPointerException
- if repl is nullpublic static java.lang.String overlayString(java.lang.String text, java.lang.String overlay, int start, int end)
text
- String to do overlaying inoverlay
- String to overlaystart
- int to start overlaying atend
- int to stop overlaying beforeNullPointerException
- if text or overlay is nullpublic static java.lang.String center(java.lang.String str, int size)
center(str, size, "")
str
- String to centersize
- int size of new StringNullPointerException
- if str is nullpublic static java.lang.String center(java.lang.String str, int size, java.lang.String delim)
str
- String to centersize
- int size of new Stringdelim
- String to buffer the new String withNullPointerException
- if str or delim is nullArithmeticException
- if delim is the empty stringpublic static java.lang.String chomp(java.lang.String str)
str
- String to chomp the newline fromNullPointerException
- if str is nullpublic static java.lang.String chomp(java.lang.String str, java.lang.String sep)
str
- String to chomp fromsep
- String to chompNullPointerException
- if str or sep is nullpublic static java.lang.String chompLast(java.lang.String str)
str
- String to chomp fromNullPointerException
- if str is nullpublic static java.lang.String chompLast(java.lang.String str, java.lang.String sep)
str
- String to chomp fromsep
- String to chompNullPointerException
- if str or sep is nullpublic static java.lang.String getChomp(java.lang.String str, java.lang.String sep)
str
- String to chomp fromsep
- String to chompNullPointerException
- if str or sep is nullpublic static java.lang.String prechomp(java.lang.String str, java.lang.String sep)
str
- String to chomp fromsep
- String to chompNullPointerException
- if str or sep is nullpublic static java.lang.String getPrechomp(java.lang.String str, java.lang.String sep)
str
- String to chomp fromsep
- String to chompNullPointerException
- if str or sep is nullpublic static java.lang.String chop(java.lang.String str)
str
- String to chop last character fromNullPointerException
- if str is nullpublic static java.lang.String chopNewline(java.lang.String str)
str
- String to chop a newline fromNullPointerException
- if str is nullpublic static java.lang.String escape(java.lang.String str)
str
- String to escape values inNullPointerException
- if str is nullpublic static java.lang.String repeat(java.lang.String str, int repeat)
str
- String to repeatrepeat
- int number of times to repeatNegativeArraySizeException
- if repeat < 0NullPointerException
- if str is nullpublic static java.lang.String rightPad(java.lang.String str, int size)
str
- String to repeatsize
- int number of times to repeatNullPointerException
- if str is nullpublic static java.lang.String rightPad(java.lang.String str, int size, java.lang.String delim)
str
- String to pad outsize
- int size to pad todelim
- String to pad withNullPointerException
- if str or delim is nullArithmeticException
- if delim is the empty stringpublic static java.lang.String leftPad(java.lang.String str, int size)
str
- String to pad outsize
- int size to pad toNullPointerException
- if str or delim is nullpublic static java.lang.String leftPad(java.lang.String str, int size, java.lang.String delim)
str
- String to pad outsize
- int size to pad todelim
- String to pad withNullPointerException
- if str or delim is nullArithmeticException
- if delim is the empty stringpublic static java.lang.String strip(java.lang.String str)
str
- the string to remove whitespace frompublic static java.lang.String strip(java.lang.String str, java.lang.String delim)
str
- the string to remove a string fromdelim
- the string to remove at start and endpublic static java.lang.String[] stripAll(java.lang.String[] strs)
strs
- the strings to remove whitespace frompublic static java.lang.String[] stripAll(java.lang.String[] strs, java.lang.String delimiter)
strs
- the strings to remove a string fromdelimiter
- the string to remove at start and endpublic static java.lang.String stripEnd(java.lang.String str, java.lang.String strip)
str
- the string to remove characters fromstrip
- the string to removepublic static java.lang.String stripStart(java.lang.String str, java.lang.String strip)
str
- the string to remove characters fromstrip
- the string to removepublic static java.lang.String upperCase(java.lang.String str)
str
- the string to uppercasepublic static java.lang.String lowerCase(java.lang.String str)
str
- the string to lowercasepublic static java.lang.String uncapitalise(java.lang.String str)
str
- the string to uncapitalisepublic static java.lang.String capitalise(java.lang.String str)
str
- the string to capitalisepublic static java.lang.String swapCase(java.lang.String str)
str
- the string to swap the case ofpublic static java.lang.String capitaliseAllWords(java.lang.String str)
str
- the string to capitalisepublic static java.lang.String getNestedString(java.lang.String str, java.lang.String tag)
str
- the string containing nested-stringtag
- the string before and after nested-stringNullPointerException
- if tag is nullpublic static java.lang.String getNestedString(java.lang.String str, java.lang.String open, java.lang.String close)
str
- the string containing nested-stringopen
- the string before nested-stringclose
- the string after nested-stringNullPointerException
- if open or close is nullpublic static int countMatches(java.lang.String str, java.lang.String sub)
str
- the string to checksub
- the substring to countNullPointerException
- if sub is nullpublic static boolean isAlpha(java.lang.String str)
str
- the string to checkpublic static boolean isAlphaSpace(java.lang.String str)
str
- the string to checkpublic static boolean isAlphanumeric(java.lang.String str)
str
- the string to checkpublic static boolean isAlphanumericSpace(java.lang.String str)
str
- the string to checkpublic static boolean isNumeric(java.lang.String str)
str
- the string to checkpublic static boolean isNumericSpace(java.lang.String str)
str
- the string to checkpublic static java.lang.String defaultString(java.lang.String str)
str
- the string to checkpublic static java.lang.String defaultString(java.lang.String str, java.lang.String defaultString)
str
- the string to checkdefaultString
- the default string to return is str is nullpublic static java.lang.String reverse(java.lang.String str)
str
- the string to reversepublic static java.lang.String reverseDelimitedString(java.lang.String str, java.lang.String delimiter)
str
- the string to reversedelimiter
- the delimiter to useprivate static void reverseArray(java.lang.Object[] array)
array
- the array to reversepublic static int getLevenshteinDistance(java.lang.String s, java.lang.String t)
s
- the first Stringt
- the second StringNullPointerException
- if s or t is nullpublic static boolean containsOnly(java.lang.String str, char[] valid)
str
- the String to checkvalid
- an array of valid chars
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |