|
|||||||||
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.
Field Summary | |
static int |
CHAR_BUFFER_SIZE
The size of the buffer to use when working with I/O (4 kB). |
Constructor Summary | |
private |
StringUtils()
Prevent construction of StringUtils instances |
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 white space 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 java.lang.String |
convertNativeToUnicode(java.lang.String input,
java.lang.String charset)
Convert a string from a native encoding to unicode. |
static java.lang.String |
convertUnicodeToNative(java.lang.String source,
java.lang.String charset)
Convert a string from unicode to bytes in a native encoding. |
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 |
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 text)
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)
Splits the provided text into a list, based on a given separator. |
static java.lang.String[] |
split(java.lang.String text,
java.lang.String separator,
int max)
Splits the provided text into a list, based on a given separator. |
static java.lang.String |
stackTrace(java.lang.Throwable throwable)
Get the stack trace from a Throwable as a String. |
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 white space 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 |
|
Field Detail |
public static int CHAR_BUFFER_SIZE
Constructor Detail |
private StringUtils()
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 deleteWhitespace(java.lang.String str)
str
- String target to delete whitespace frompublic 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 stringpublic 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 stringpublic static int indexOfAny(java.lang.String str, java.lang.String[] searchStrs)
str
- the string to checksearchStrs
- the strings to search forpublic static int lastIndexOfAny(java.lang.String str, java.lang.String[] searchStrs)
str
- the string to checksearchStrs
- the strings to search forpublic 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 text)
str
- the string to parsepublic static java.lang.String[] split(java.lang.String text, java.lang.String separator)
str
- the string to parseseparator
- The separator character. If null
, splits
on whitespace.public static java.lang.String[] split(java.lang.String text, java.lang.String separator, int max)
str
- the string to parseseparator
- The separator character. 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 maximumpublic 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 beforepublic static java.lang.String center(java.lang.String str, int size)
str
- String to centersize
- int size of new Stringpublic 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 withpublic static java.lang.String chomp(java.lang.String str)
str
- String to chomp the newline frompublic static java.lang.String chomp(java.lang.String str, java.lang.String sep)
str
- String to chomp fromsep
- String to chomppublic static java.lang.String chompLast(java.lang.String str)
str
- String to chomp frompublic static java.lang.String chompLast(java.lang.String str, java.lang.String sep)
str
- String to chomp fromsep
- String to chomppublic static java.lang.String getChomp(java.lang.String str, java.lang.String sep)
str
- String to chomp fromsep
- String to chomppublic static java.lang.String prechomp(java.lang.String str, java.lang.String sep)
str
- String to chomp fromsep
- String to chomppublic static java.lang.String getPrechomp(java.lang.String str, java.lang.String sep)
str
- String to chomp fromsep
- String to chomppublic static java.lang.String chop(java.lang.String str)
str
- String to chop last character frompublic static java.lang.String chopNewline(java.lang.String str)
str
- String to chop a newline fromString
- without newline on endpublic static java.lang.String escape(java.lang.String str)
str
- String to escape values inpublic static java.lang.String repeat(java.lang.String str, int repeat)
str
- String to repeatrepeat
- int number of times to repeatpublic static java.lang.String rightPad(java.lang.String str, int size)
str
- String to repeatsize
- int number of times to repeatpublic 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 withpublic static java.lang.String leftPad(java.lang.String str, int size)
str
- String to pad outsize
- int size to pad topublic 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 withpublic 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 fromdelim
- 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-stringpublic 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-stringpublic static int countMatches(java.lang.String str, java.lang.String sub)
str
- the string to checkpublic 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)
public static java.lang.String stackTrace(java.lang.Throwable throwable)
This method uses printStackTrace() internally to obtain the stack trace.
throwable
- the throwable to extract a stack trace fromThrowable.printStackTrace()
public static int getLevenshteinDistance(java.lang.String s, java.lang.String t)
public static java.lang.String convertUnicodeToNative(java.lang.String source, java.lang.String charset) throws java.io.IOException
convertNativeToUnicode(String, String)
will convert
strings in native encodings into unicode. This method is
generally used to create a String
for use as
output, and is useful when dealing with I18N.source
- String the unicode string to convertcharset
- String the name of the charset into which to
convert.convertNativeToUnicode(String, String)
public static java.lang.String convertNativeToUnicode(java.lang.String input, java.lang.String charset) throws java.io.IOException
String
for
use as input, and is useful when dealing with I18N.input
- String the input to convert from native encoding
to unicode.charset
- String the charset from which to convert.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |