public class StringUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static char[] |
HEX_TABLE |
| Constructor and Description |
|---|
StringUtil() |
| Modifier and Type | Method and Description |
|---|---|
static String |
capitalize(String string0)
Safely capitalizes a string by converting the first character to upper
case.
|
static String |
compressQuotes(String source,
String quotes)
Compress 2 adjacent (single or double) quotes into a single (s or d)
quote when found in the middle of a String.
|
static boolean |
contains(String[] strings,
String targetString)
Checks if the targetString is contained within the array of strings.
|
static boolean |
containsOnlyDigits(String string0)
Checks if a string contains only digits.
|
static String |
escapeXml(String value)
Escapes the characters in a String using XML entities.
|
static String |
formatForPrint(String input)
Used to print out a string for error messages,
chops is off at 60 chars for historical reasons.
|
static byte[] |
fromHexString(String hexString)
Deprecated.
Please use new utility class HexUtil
|
static byte[] |
fromHexString(String hexString,
int offset,
int length)
Deprecated.
Please use new utility class HexUtil
|
static byte[] |
getAsciiBytes(String input)
Get 7-bit ASCII character array from input String.
|
static String |
getAsciiString(byte[] input) |
static String |
hexDump(String prefix,
byte[] data)
Convert a byte array to a human-readable String for debugging purposes.
|
static int |
indexOf(String[] strings,
String targetString)
Finds the first occurrence of the targetString in the array of strings.
|
static boolean |
isEmpty(String string0)
Checks if the string is an empty value which is true if the string is
null or if the string represents an empty string of "".
|
static boolean |
isEqual(String string0,
String string1) |
static boolean |
isEqual(String string0,
String string1,
boolean caseSensitive)
Checks if both strings are equal to each other.
|
static boolean |
isPrintableChar(char ch)
Return true if the character is printable in ASCII.
|
static boolean |
isSafeChar(char ch)
Returns true if the char is considered a "safe" char.
|
static boolean |
isSafeString(String string0)
Returns true if the String is considered a "safe" string where only specific
characters are allowed to be used.
|
static String |
normalizeSQLIdentifier(String id)
Normalize a SQL identifer, up-casing if
|
static String |
quoteStringLiteral(String string)
Quote a string so that it can be used as a string literal in an
SQL statement.
|
static String |
readToString(InputStream in) |
static String |
removeAllCharsExceptDigits(String str0)
Removes all other characters from a string except digits.
|
static String |
slice(String value,
int beginOffset,
int endOffset,
boolean trim)
Return a slice (substring) of the passed in value, optionally trimmed.
|
static String[] |
split(String str,
char delim)
Splits a string around matches of the given delimiter character.
|
static boolean |
SQLEqualsIgnoreCase(String s1,
String s2)
Compares two strings
Strings will be uppercased in english and compared
equivalent to s1.equalsIgnoreCase(s2)
throws NPE if s1 is null
|
static String |
SQLToUpperCase(String s)
Convert string to uppercase
Always use the java.util.ENGLISH locale
|
static String |
stringify(int[] raw)
Turn an array of ints into a printable string.
|
static String |
stripQuotes(String string0)
If present, this method will strip off the leading and trailing "
character in the string parameter.
|
static String |
substituteWithEnvironment(String string0)
Searches the string for occurrences of the pattern $ENV{key} and
attempts to replace this pattern with a value from the System environment
obtained using the 'key'.
|
static String |
substituteWithProperties(String string0,
String startStr,
String endStr,
Properties properties)
Searches string for occurrences of a pattern, extracts out a key name
between the startStr and endStr tokens, then attempts to replace the
property value into the string.
|
static byte[] |
toHexByte(String hexString,
int offset,
int length)
Deprecated.
Please use new utility class HexUtil
|
static String |
toHexString(byte[] bytes)
Deprecated.
Please use new utility class HexUtil
|
static String |
toHexString(byte[] bytes,
int offset,
int length)
Deprecated.
Please use new utility class HexUtil
|
static String[] |
toStringArray(Object[] objArray)
A method that receive an array of Objects and return a
String array representation of that array.
|
static String |
toStringWithNullAsEmpty(Object obj)
Returns the value from calling "toString()" on the object, but is a safe
version that gracefully handles NULL objects by returning a String of "".
|
static String |
toStringWithNullAsNull(Object obj)
Returns the value from calling "toString()" on the object, but is a safe
version that gracefully handles NULL objects by returning null (rather
than causing a NullPointerException).
|
static String |
toStringWithNullAsReplaced(Object obj)
Returns the value from calling "toString()" on the object, but is a safe
version that gracefully handles NULL objects by returning a String of "
|
static String |
trimTrailing(String str)
Trim off trailing blanks but not leading blanks
|
static String |
truncate(String value,
int length)
Truncate a String to the given length with no warnings
or error raised if it is bigger.
|
static String |
uncapitalize(String string0)
Safely uncapitalizes a string by converting the first character to lower
case.
|
public static String substituteWithEnvironment(String string0) throws SubstitutionException
string0 - The string to perform substitution on such as "Hello $ENV{USERNAME}".
This string may be null, empty, or contain one or more substitutions.SubstitutionException - Thrown if a starting string was found, but the
ending string was not. Also, thrown if a key value was empty such
as using "$ENV{}". Finally, thrown if the property key was not
found in the properties object (could not be replaced).substituteWithProperties(java.lang.String, java.lang.String, java.lang.String, java.util.Properties)public static String substituteWithProperties(String string0, String startStr, String endStr, Properties properties) throws SubstitutionException
string0 - The string to perform substitution on such as "Hello $ENV{TEST}".
This string may be null, empty, or contain one or more substitutions.startStr - The string that marks the start of a replacement key such
as "$ENV{" if the final search pattern you wanted was "$ENV{endStr - The string that marks the end of a replacement key such
as "}" if the final search pattern you wanted was "$ENV{properties - The property keys and associated values to use for
replacement.SubstitutionException - Thrown if a starting string was found, but the
ending string was not. Also, thrown if a key value was empty such
as using "$ENV{}". Finally, thrown if the property key was not
found in the properties object (could not be replaced).substituteWithEnvironment(java.lang.String)public static boolean isSafeString(String string0)
public static boolean isSafeChar(char ch)
isSafeString(java.lang.String)public static String capitalize(String string0)
string0 - The string to capitalizepublic static String uncapitalize(String string0)
string0 - The string to uncapitalizepublic static boolean contains(String[] strings, String targetString)
strings - The array of strings to search.targetString - The string to search forpublic static int indexOf(String[] strings, String targetString)
strings - The array of strings to search.targetString - The string to search forpublic static String stripQuotes(String string0)
public static boolean containsOnlyDigits(String string0)
public static String[] split(String str, char delim)
String.split(String regex), which is not available
on a JSR169/Java ME platform.str - the string to be splitdelim - the delimiterNullPointerException - if str is nullpublic static final String formatForPrint(String input)
public static String[] toStringArray(Object[] objArray)
public static byte[] getAsciiBytes(String input)
public static String getAsciiString(byte[] input)
public static String trimTrailing(String str)
str - public static String truncate(String value, int length)
value - String to be truncatedlength - Maximum length of stringpublic static String slice(String value, int beginOffset, int endOffset, boolean trim)
value - Value to slice, must be non-null.beginOffset - Inclusive start characterendOffset - Inclusive end charactertrim - To trim or not to trim@Deprecated public static String toHexString(byte[] bytes)
HexUtil.toHexString(byte[])@Deprecated public static String toHexString(byte[] bytes, int offset, int length)
@Deprecated public static byte[] toHexByte(String hexString, int offset, int length)
@Deprecated public static byte[] fromHexString(String hexString)
string0 - The string containing the hex-encoded data.HexUtil.toByteArray(java.lang.CharSequence)@Deprecated public static byte[] fromHexString(String hexString, int offset, int length)
s - String to convertoffset - starting character (zero based) to convert.length - number of characters to convert.HexUtil.toByteArray(java.lang.CharSequence, int, int)public static boolean isPrintableChar(char ch)
public static String hexDump(String prefix, byte[] data)
public static String SQLToUpperCase(String s)
s - string to uppercasepublic static boolean SQLEqualsIgnoreCase(String s1, String s2)
s1 - first string to compares2 - second string to comparepublic static String normalizeSQLIdentifier(String id)
id - syntacically correct SQL identifierpublic static String compressQuotes(String source, String quotes)
source - string to be compressedquotes - string containing two single or double quotes.public static String quoteStringLiteral(String string)
string - the string to quotepublic static String stringify(int[] raw)
public static boolean isEmpty(String string0)
string0 - The string to checkpublic static String toStringWithNullAsEmpty(Object obj)
obj - The object to call toString() on. Safely handles a null object.toStringWithNullAsNull(java.lang.Object)public static String toStringWithNullAsReplaced(Object obj)
obj - The object to call toString() on. Safely handles a null object.toStringWithNullAsEmpty(java.lang.Object)public static String toStringWithNullAsNull(Object obj)
obj - The object to call toString() on. Safely handles a null object.toStringWithNullAsEmpty(java.lang.Object)public static boolean isEqual(String string0, String string1, boolean caseSensitive)
string0 - The string to comparestring1 - The other string to compare withcaseSensitive - If true a case sensitive comparison will be made,
otherwise equalsIgnoreCase will be used.public static String readToString(InputStream in) throws IOException
IOExceptionpublic static String escapeXml(String value)
value - The string to escapepublic static String removeAllCharsExceptDigits(String str0)
str0 - The string to clean upCopyright © 2012-2015 Cloudhopper by Twitter. All Rights Reserved.