public class StringUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
addAsterisk(java.lang.String s,
int index)
Add an asterisk ('[*]') at the given position.
|
static void |
appendZeroPadded(java.lang.StringBuilder buff,
int length,
long positiveValue)
Append a zero-padded number to a string builder.
|
static java.lang.String |
arrayCombine(java.lang.String[] list,
char separatorChar)
Combine an array of strings to one array using the given separator
character.
|
static java.lang.String[] |
arraySplit(java.lang.String s,
char separatorChar,
boolean trim)
Split a string into an array of strings using the given separator.
|
static java.lang.String |
cache(java.lang.String s)
Get the string from the cache if possible.
|
static void |
clearCache()
Clear the cache.
|
static char[] |
cloneCharArray(char[] chars)
Create a new char array and copy all the data.
|
static java.lang.String |
convertBytesToHex(byte[] value)
Convert a byte array to a hex encoded string.
|
static java.lang.String |
convertBytesToHex(byte[] value,
int len)
Convert a byte array to a hex encoded string.
|
static byte[] |
convertHexToBytes(java.lang.String s)
Convert a hex encoded string to a byte array.
|
static java.lang.String |
enclose(java.lang.String s)
Enclose a string with '(' and ')' if this is not yet done.
|
static java.lang.String |
escapeMetaDataPattern(java.lang.String pattern)
Escape table or schema patterns used for DatabaseMetaData functions.
|
static java.lang.String |
indent(java.lang.String s)
Indents a string with 4 spaces.
|
static java.lang.String |
indent(java.lang.String s,
int spaces,
boolean newline)
Indents a string with spaces.
|
static boolean |
isNullOrEmpty(java.lang.String s)
Check if a String is null or empty (the length is null).
|
static boolean |
isNumber(java.lang.String s)
Check if this string is a decimal number.
|
static java.lang.String |
javaDecode(java.lang.String s)
Decode a text that is encoded as a Java string literal.
|
static java.lang.String |
javaEncode(java.lang.String s)
Convert a string to a Java literal using the correct escape sequences.
|
static java.lang.String |
pad(java.lang.String string,
int n,
java.lang.String padding,
boolean right)
Pad a string.
|
static java.lang.String |
quoteIdentifier(java.lang.String s)
Enclose a string with double quotes.
|
static java.lang.String |
quoteJavaIntArray(int[] array)
Convert an int array to the Java source code that represents this array.
|
static java.lang.String |
quoteJavaString(java.lang.String s)
Convert a string to the Java literal and enclose it with double quotes.
|
static java.lang.String |
quoteJavaStringArray(java.lang.String[] array)
Convert a string array to the Java source code that represents this
array.
|
static java.lang.String |
quoteRemarkSQL(java.lang.String sql)
In a string, replace block comment marks with /++ ..
|
static java.lang.String |
quoteStringSQL(java.lang.String s)
Convert a string to a SQL literal.
|
static java.lang.String |
replaceAll(java.lang.String s,
java.lang.String before,
java.lang.String after)
Replace all occurrences of the before string with the after string.
|
static boolean |
startsWithIgnoreCase(java.lang.String s,
java.lang.String start)
Check is a string starts with another string, ignoring the case.
|
static java.lang.String |
toLowerEnglish(java.lang.String s)
Convert a string to lowercase using the English locale.
|
static java.lang.String |
toUpperEnglish(java.lang.String s)
Convert a string to uppercase using the English locale.
|
static java.lang.String |
trim(java.lang.String s,
boolean leading,
boolean trailing,
java.lang.String sp)
Trim a character from a string.
|
static java.lang.String |
unEnclose(java.lang.String s)
Remove enclosing '(' and ')' if this text is enclosed.
|
static java.lang.String |
urlDecode(java.lang.String encoded)
Decode the URL to a string.
|
static java.lang.String |
urlEncode(java.lang.String s)
Encode the string as an URL.
|
static java.lang.String |
xmlAttr(java.lang.String name,
java.lang.String value)
Creates an XML attribute of the form name="value".
|
static java.lang.String |
xmlCData(java.lang.String data)
Converts the data to a CDATA element.
|
static java.lang.String |
xmlComment(java.lang.String data)
Escapes a comment.
|
static java.lang.String |
xmlNode(java.lang.String name,
java.lang.String attributes,
java.lang.String content)
Create an XML node with optional attributes and content.
|
static java.lang.String |
xmlNode(java.lang.String name,
java.lang.String attributes,
java.lang.String content,
boolean indent)
Create an XML node with optional attributes and content.
|
static java.lang.String |
xmlStartDoc()
Returns <?xml version="1.0"?>
|
static java.lang.String |
xmlText(java.lang.String text)
Escapes an XML text element.
|
static java.lang.String |
xmlText(java.lang.String text,
boolean escapeNewline)
Escapes an XML text element.
|
public static java.lang.String toUpperEnglish(java.lang.String s)
s - the test to convertpublic static java.lang.String toLowerEnglish(java.lang.String s)
s - the text to convertpublic static boolean startsWithIgnoreCase(java.lang.String s,
java.lang.String start)
s - the string to check (must be longer than start)start - the prefix of spublic static java.lang.String quoteStringSQL(java.lang.String s)
s - the text to convert.public static java.lang.String javaEncode(java.lang.String s)
s - the text to convertpublic static java.lang.String addAsterisk(java.lang.String s,
int index)
s - the textindex - the positionpublic static java.lang.String javaDecode(java.lang.String s)
s - the encoded stringpublic static java.lang.String quoteJavaString(java.lang.String s)
s - the text to convertpublic static java.lang.String quoteJavaStringArray(java.lang.String[] array)
array - the string arraypublic static java.lang.String quoteJavaIntArray(int[] array)
array - the int arraypublic static java.lang.String enclose(java.lang.String s)
s - the stringpublic static java.lang.String unEnclose(java.lang.String s)
s - the potentially enclosed stringpublic static java.lang.String urlEncode(java.lang.String s)
s - the string to encodepublic static java.lang.String urlDecode(java.lang.String encoded)
encoded - the encoded URLpublic static java.lang.String[] arraySplit(java.lang.String s,
char separatorChar,
boolean trim)
s - the string to splitseparatorChar - the separator charactertrim - whether each element should be trimmedpublic static java.lang.String arrayCombine(java.lang.String[] list,
char separatorChar)
list - the string arrayseparatorChar - the separator characterpublic static java.lang.String xmlAttr(java.lang.String name,
java.lang.String value)
name - the attribute namevalue - the attribute valuepublic static java.lang.String xmlNode(java.lang.String name,
java.lang.String attributes,
java.lang.String content)
name - the element nameattributes - the attributes (may be null)content - the content (may be null)public static java.lang.String xmlNode(java.lang.String name,
java.lang.String attributes,
java.lang.String content,
boolean indent)
name - the element nameattributes - the attributes (may be null)content - the content (may be null)indent - whether to indent the content if it contains a newlinepublic static java.lang.String indent(java.lang.String s)
s - the stringpublic static java.lang.String indent(java.lang.String s,
int spaces,
boolean newline)
s - the stringspaces - the number of spacesnewline - append a newline if there is nonepublic static java.lang.String xmlComment(java.lang.String data)
data - the comment textpublic static java.lang.String xmlCData(java.lang.String data)
data - the text datapublic static java.lang.String xmlStartDoc()
public static java.lang.String xmlText(java.lang.String text)
text - the text datapublic static java.lang.String xmlText(java.lang.String text,
boolean escapeNewline)
text - the text dataescapeNewline - whether to escape newlinespublic static java.lang.String replaceAll(java.lang.String s,
java.lang.String before,
java.lang.String after)
String.replaceAll(String, String) this method reads before
and after arguments as plain strings and if before argument
is an empty string this method returns original string s.s - the stringbefore - the old textafter - the new textpublic static java.lang.String quoteIdentifier(java.lang.String s)
s - the textpublic static boolean isNullOrEmpty(java.lang.String s)
s - the string to checkpublic static java.lang.String quoteRemarkSQL(java.lang.String sql)
sql - the stringpublic static java.lang.String pad(java.lang.String string,
int n,
java.lang.String padding,
boolean right)
string - the original stringn - the target lengthpadding - the padding stringright - true if the padding should be appended at the endpublic static char[] cloneCharArray(char[] chars)
chars - the char array (may be null)public static java.lang.String trim(java.lang.String s,
boolean leading,
boolean trailing,
java.lang.String sp)
s - the stringleading - if leading characters should be removedtrailing - if trailing characters should be removedsp - what to remove (only the first character is used)
or null for a spacepublic static java.lang.String cache(java.lang.String s)
s - the original stringpublic static void clearCache()
public static byte[] convertHexToBytes(java.lang.String s)
s - the hex encoded stringpublic static java.lang.String convertBytesToHex(byte[] value)
value - the byte arraypublic static java.lang.String convertBytesToHex(byte[] value,
int len)
value - the byte arraylen - the number of bytes to encodepublic static boolean isNumber(java.lang.String s)
s - the stringpublic static void appendZeroPadded(java.lang.StringBuilder buff,
int length,
long positiveValue)
buff - the string builderlength - the number of characters to appendpositiveValue - the number to appendpublic static java.lang.String escapeMetaDataPattern(java.lang.String pattern)
pattern - the pattern