|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.util.StringUtils
Miscellaneous string utility methods. Mainly for internal use within the framework; consider Jakarta's Commons Lang for a more comprehensive suite of string utilities.
This class delivers some simple functionality that should really be provided by the core Java String and StringBuffer classes, such as the ability to replace all occurrences of a given substring in a target string. It also provides easy-to-use methods to convert between delimited strings, such as CSV strings, and collections and arrays.
org.apache.commons.lang.StringUtils
Constructor Summary | |
StringUtils()
|
Method Summary | |
static java.lang.String[] |
addStringToArray(java.lang.String[] arr,
java.lang.String s)
Append the given String to the given String array, returning a new array consisting of the input array contents plus the given String. |
static java.lang.String |
arrayToCommaDelimitedString(java.lang.Object[] arr)
Convenience method to return a String array as a CSV String. |
static java.lang.String |
arrayToDelimitedString(java.lang.Object[] arr,
java.lang.String delim)
Convenience method to return a String array as a delimited (e.g. |
static java.lang.String |
collectionToCommaDelimitedString(java.util.Collection c)
Convenience method to return a Collection as a CSV String. |
static java.lang.String |
collectionToDelimitedString(java.util.Collection c,
java.lang.String delim)
Convenience method to return a Collection as a delimited (e.g. |
static java.util.Set |
commaDelimitedListToSet(java.lang.String s)
Convenience method to convert a CSV string list to a set. |
static java.lang.String[] |
commaDelimitedListToStringArray(java.lang.String s)
Convert a CSV list into an array of Strings. |
static int |
countOccurrencesOf(java.lang.String s,
java.lang.String sub)
Count the occurrences of the substring in string s. |
static java.lang.String |
delete(java.lang.String inString,
java.lang.String pattern)
Delete all occurrences of the given substring. |
static java.lang.String |
deleteAny(java.lang.String inString,
java.lang.String chars)
Delete any character in a given string. |
static java.lang.String[] |
delimitedListToStringArray(java.lang.String s,
java.lang.String delim)
Take a String which is a delimited list and convert it to a String array. |
static boolean |
hasLength(java.lang.String str)
Checks if a String has length. |
static boolean |
hasText(java.lang.String str)
Checks if a String has text. |
static java.lang.String |
replace(java.lang.String inString,
java.lang.String oldPattern,
java.lang.String newPattern)
Replace all occurences of a substring within a string with another string. |
static java.lang.String[] |
tokenizeToStringArray(java.lang.String s,
java.lang.String delimiters,
boolean trimTokens,
boolean ignoreEmptyTokens)
Tokenize the given String into a String array via a StringTokenizer. |
static java.lang.String |
uncapitalize(java.lang.String str)
Uncapitalizes a String , changing the first letter to
lower case as per Character.toLowerCase(char) . |
static java.lang.String |
unqualify(java.lang.String qualifiedName)
Unqualifies a string qualified by a '.' dot character. |
static java.lang.String |
unqualify(java.lang.String qualifiedName,
char separator)
Unqualifies a string qualified by a separator character. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public StringUtils()
Method Detail |
public static int countOccurrencesOf(java.lang.String s, java.lang.String sub)
s
- string to search in. Return 0 if this is null.sub
- string to search for. Return 0 if this is null.public static java.lang.String replace(java.lang.String inString, java.lang.String oldPattern, java.lang.String newPattern)
inString
- String to examineoldPattern
- String to replacenewPattern
- String to insert
public static java.lang.String delete(java.lang.String inString, java.lang.String pattern)
pattern
- the pattern to delete all occurrences ofpublic static java.lang.String deleteAny(java.lang.String inString, java.lang.String chars)
chars
- characters to delete.
E.g. az\n will delete as, zs and new lines.public static java.lang.String[] tokenizeToStringArray(java.lang.String s, java.lang.String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)
s
- the String to tokenizedelimiters
- the delimiter characters, assembled as StringtrimTokens
- trim the tokens via String.trimignoreEmptyTokens
- omit empty tokens from the result array
StringTokenizer
,
String.trim()
public static java.lang.String[] delimitedListToStringArray(java.lang.String s, java.lang.String delim)
s
- Stringdelim
- delim (this will not be returned)
public static java.lang.String[] commaDelimitedListToStringArray(java.lang.String s)
s
- CSV list
public static java.util.Set commaDelimitedListToSet(java.lang.String s)
s
- CSV String
public static java.lang.String arrayToDelimitedString(java.lang.Object[] arr, java.lang.String delim)
arr
- array to display. Elements may be of any type (toString
will be called on each element).delim
- delimiter to use (probably a ,)public static java.lang.String collectionToDelimitedString(java.util.Collection c, java.lang.String delim)
c
- Collection to displaydelim
- delimiter to use (probably a ",")public static java.lang.String arrayToCommaDelimitedString(java.lang.Object[] arr)
arr
- array to display. Elements may be of any type (toString
will be called on each element).public static java.lang.String collectionToCommaDelimitedString(java.util.Collection c)
c
- Collection to displaypublic static java.lang.String[] addStringToArray(java.lang.String[] arr, java.lang.String s)
arr
- the array to append tos
- the String to append
public static boolean hasLength(java.lang.String str)
StringUtils.hasLength(null) = false StringUtils.hasLength("") = false StringUtils.hasLength(" ") = true StringUtils.hasLength("Hello") = true
str
- the String to check, may be null
true
if the String is has length and is not nullpublic static boolean hasText(java.lang.String str)
true
if the string not null, it's length is > 0
, and
it has at least one non-whitespace character.
StringUtils.hasText(null) = false
StringUtils.hasText("") = false
StringUtils.hasText(" ") = false
StringUtils.hasText("12345") = true
StringUtils.hasText(" 12345 ") = true
- Parameters:
str
- the String to check, may be null
- Returns:
true
if the String is not null, length > 0,
and not whitespace only
public static java.lang.String unqualify(java.lang.String qualifiedName)
qualifiedName
- the qualified namepublic static java.lang.String unqualify(java.lang.String qualifiedName, char separator)
qualifiedName
- the qualified nameseparator
- the separatorpublic static java.lang.String uncapitalize(java.lang.String str)
String
, changing the first letter to
lower case as per Character.toLowerCase(char)
.
No other letters are changed.
str
- the String to uncapitalize, may be null
null
if null
String input
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |