public final class TextUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
firstCharLower(String text)
Tranforms the given
String to the similar String,
but starting with a lowercase. |
static String |
firstCharUpper(String text)
Tranforms the given
String to the similar String,
but starting with an uppercase. |
static boolean |
isEmpty(String s)
Determines if the specified string is
null or an empty
string. |
static String |
quote(Object o)
Quotes the textual presentation (returned by
toString()) of
the specified object, or returns "(null)" if the object is
null. |
static String |
quote(String s)
Quotes the specified string, or returns
"(null)" if it is
null. |
static String |
removeCharacter(char charToRemove,
String text)
Removes the given character from the given
String. |
static String |
replace(String s,
Properties replacements,
String prefix,
String suffix)
Replaces substrings in a string.
|
static String |
trim(String s,
String ifEmpty)
Trims the specified string, or returns an empty string if the argument
is
null. |
public static String quote(String s)
"(null)" if it is
null.s - the input string, or null.s != null the quoted string, otherwise the string
"(null)".public static String quote(Object o)
toString()) of
the specified object, or returns "(null)" if the object is
null.o - the object, or null.o != null then o.toString() quoted,
otherwise the string "(null)".public static boolean isEmpty(String s)
null or an empty
string.s - the string, or null.true if s == null || s.length() < 1.public static String trim(String s, String ifEmpty)
null.s - the string, or null.ifEmpty - the string to return if
s == null || s.trim().length < 1.String.trim()) or
ifEmpty if
s == null or s.trim().length < 1.public static String replace(String s, Properties replacements, String prefix, String suffix) throws IllegalArgumentException
Properties object. A prefix and a suffix can be
specified. These are prepended/appended to each of the search keys.
Example: If you have a string "Hello ${name}" and you
would like to replace "${name}" with "John"
and you would like to replace ${surname} with
"Doe", use the following code:
String s = "Hello ${name}";
Properties replacements = new Properties();
replacements.put("name", "John");
replacements.put("surname", "Doe");
StringUtils.replace(s, replacements, "${", "}");
The result string will be "Hello John".s - the text string to which replacements should be applied, not null.replacements - the replacements to apply, not null.prefix - the optional prefix for the search keys, or null.suffix - the optional prefix for the search keys, or null.IllegalArgumentException - if one of the mandatory arguments is missing.public static String firstCharUpper(String text)
String to the similar String,
but starting with an uppercase.text - the text to transform, can be nullnull is returned if the text was null.public static String firstCharLower(String text)
String to the similar String,
but starting with a lowercase.text - the text to transform, can be nullnull is returned if the text was null.public static String removeCharacter(char charToRemove, String text)
String.charToRemove - the character that should be removed from the String.text - the text from which the charecter should be removed, can be null.null if the input text is null.See http://www.xins.org/.