public class StringUtils extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
addAsterisk(String s,
int index)
Add an asterisk ('[*]') at the given position.
|
static StringBuilder |
appendHex(StringBuilder builder,
long x,
int bytes)
Appends specified number of trailing bytes from unsigned long value to a
specified string builder.
|
static StringBuilder |
appendTwoDigits(StringBuilder builder,
int positiveValue)
Append a zero-padded number from 00 to 99 to a string builder.
|
static StringBuilder |
appendZeroPadded(StringBuilder builder,
int length,
long positiveValue)
Append a zero-padded number to a string builder.
|
static String |
arrayCombine(String[] list,
char separatorChar)
Combine an array of strings to one array using the given separator
character.
|
static String[] |
arraySplit(String s,
char separatorChar,
boolean trim)
Split a string into an array of strings using the given separator.
|
static String |
cache(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 String |
convertBytesToHex(byte[] value)
Convert a byte array to a hex encoded string.
|
static String |
convertBytesToHex(byte[] value,
int len)
Convert a byte array to a hex encoded string.
|
static StringBuilder |
convertBytesToHex(StringBuilder builder,
byte[] value)
Convert a byte array to a hex encoded string and appends it to a specified string builder.
|
static StringBuilder |
convertBytesToHex(StringBuilder builder,
byte[] value,
int len)
Convert a byte array to a hex encoded string and appends it to a specified string builder.
|
static byte[] |
convertHexToBytes(String s)
Convert a hex encoded string to a byte array.
|
static ByteArrayOutputStream |
convertHexWithSpacesToBytes(ByteArrayOutputStream baos,
String s,
int start,
int end)
Parses a hex encoded string with possible space separators and appends
the decoded binary string to the specified output stream.
|
static String |
decodeUnicodeStringSQL(String s,
int uencode)
Decodes a Unicode SQL string.
|
static String |
escapeMetaDataPattern(String pattern)
Escape table or schema patterns used for DatabaseMetaData functions.
|
static StringBuilder |
indent(StringBuilder builder,
String s,
int spaces,
boolean newline)
Indents a string with spaces and appends it to a specified builder.
|
static boolean |
isNullOrEmpty(String s)
Check if a String is null or empty (the length is null).
|
static boolean |
isNumber(String s)
Check if this string is a decimal number.
|
static boolean |
isWhitespaceOrEmpty(String s)
Check if the specified string is empty or contains only whitespace.
|
static String |
javaDecode(String s)
Decode a text that is encoded as a Java string literal.
|
static String |
javaEncode(String s)
Convert a string to a Java literal using the correct escape sequences.
|
static void |
javaEncode(String s,
StringBuilder buff,
boolean forSQL)
Convert a string to a Java literal using the correct escape sequences.
|
static String |
pad(String string,
int n,
String padding,
boolean right)
Pad a string.
|
static int |
parseUInt31(String s,
int start,
int end)
Parses an unsigned 31-bit integer.
|
static String |
quoteIdentifier(String s)
Enclose a string with double quotes.
|
static StringBuilder |
quoteIdentifier(StringBuilder builder,
String s)
Enclose a string with double quotes and append it to the specified
string builder.
|
static String |
quoteJavaIntArray(int[] array)
Convert an int array to the Java source code that represents this array.
|
static String |
quoteJavaString(String s)
Convert a string to the Java literal and enclose it with double quotes.
|
static String |
quoteJavaStringArray(String[] array)
Convert a string array to the Java source code that represents this
array.
|
static String |
quoteStringSQL(String s)
Convert a string to a SQL literal.
|
static StringBuilder |
quoteStringSQL(StringBuilder builder,
String s)
Convert a string to a SQL character string literal.
|
static String |
replaceAll(String s,
String before,
String after)
Replace all occurrences of the before string with the after string.
|
static String |
toLowerEnglish(String s)
Convert a string to lowercase using the English locale.
|
static String |
toUpperEnglish(String s)
Convert a string to uppercase using the English locale.
|
static String |
trim(String s,
boolean leading,
boolean trailing,
String sp)
Trim a character from a string.
|
static StringBuilder |
trimSubstring(StringBuilder builder,
String s,
int beginIndex,
int endIndex)
Trim a whitespace from a substring and append it to a specified string
builder.
|
static String |
trimSubstring(String s,
int beginIndex)
Trim a whitespace from a substring.
|
static String |
trimSubstring(String s,
int beginIndex,
int endIndex)
Trim a whitespace from a substring.
|
static String |
truncateString(String s,
int maximumLength)
Truncates the specified string to the specified length.
|
static String |
urlDecode(String encoded)
Decode the URL to a string.
|
static String |
urlEncode(String s)
Encode the string as a URL.
|
static String |
xmlAttr(String name,
String value)
Creates an XML attribute of the form name="value".
|
static String |
xmlCData(String data)
Converts the data to a CDATA element.
|
static String |
xmlComment(String data)
Escapes a comment.
|
static String |
xmlNode(String name,
String attributes,
String content)
Create an XML node with optional attributes and content.
|
static String |
xmlNode(String name,
String attributes,
String content,
boolean indent)
Create an XML node with optional attributes and content.
|
static String |
xmlStartDoc()
Returns <?
|
static String |
xmlText(String text)
Escapes an XML text element.
|
static String |
xmlText(String text,
boolean escapeNewline)
Escapes an XML text element.
|
public static String toUpperEnglish(String s)
s - the test to convertpublic static String toLowerEnglish(String s)
s - the text to convertpublic static String quoteStringSQL(String s)
s - the text to convert.public static StringBuilder quoteStringSQL(StringBuilder builder, String s)
builder - string builder to append result tos - the text to convertpublic static String decodeUnicodeStringSQL(String s, int uencode)
s - the string to decodeuencode - the code point of UENCODE character, or '\\'DbException - on format exceptionpublic static String javaEncode(String s)
s - the text to convertpublic static void javaEncode(String s, StringBuilder buff, boolean forSQL)
s - the text to convertbuff - the Java representation to returnforSQL - true if we embedding this inside a STRINGDECODE SQL commandpublic static String addAsterisk(String s, int index)
s - the textindex - the positionpublic static String javaDecode(String s)
s - the encoded stringpublic static String quoteJavaString(String s)
s - the text to convertpublic static String quoteJavaStringArray(String[] array)
array - the string arraypublic static String quoteJavaIntArray(int[] array)
array - the int arraypublic static String urlEncode(String s)
s - the string to encodepublic static String urlDecode(String encoded)
encoded - the encoded URLpublic static String[] arraySplit(String s, char separatorChar, boolean trim)
s - the string to splitseparatorChar - the separator charactertrim - whether each element should be trimmedpublic static String arrayCombine(String[] list, char separatorChar)
list - the string arrayseparatorChar - the separator characterpublic static String xmlAttr(String name, String value)
name - the attribute namevalue - the attribute valuepublic static String xmlNode(String name, String attributes, String content)
name - the element nameattributes - the attributes (may be null)content - the content (may be null)public static String xmlNode(String name, String attributes, 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 StringBuilder indent(StringBuilder builder, String s, int spaces, boolean newline)
builder - string builder to append tos - the stringspaces - the number of spacesnewline - append a newline if there is nonepublic static String xmlComment(String data)
data - the comment textpublic static String xmlCData(String data)
data - the text datapublic static String xmlStartDoc()
public static String xmlText(String text)
text - the text datapublic static String xmlText(String text, boolean escapeNewline)
text - the text dataescapeNewline - whether to escape newlinespublic static String replaceAll(String s, String before, 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 String quoteIdentifier(String s)
s - the textpublic static StringBuilder quoteIdentifier(StringBuilder builder, String s)
builder - string builder to append tos - the textpublic static boolean isNullOrEmpty(String s)
s - the string to checkpublic static String pad(String string, int n, 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 String trim(String s, boolean leading, boolean trailing, 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 String trimSubstring(String s, int beginIndex)
substring(beginIndex).trim().s - the stringbeginIndex - start index of substring (inclusive)public static String trimSubstring(String s, int beginIndex, int endIndex)
substring(beginIndex, endIndex).trim().s - the stringbeginIndex - start index of substring (inclusive)endIndex - end index of substring (exclusive)public static StringBuilder trimSubstring(StringBuilder builder, String s, int beginIndex, int endIndex)
builder.append(substring(beginIndex, endIndex).trim()).builder - string builder to append tos - the stringbeginIndex - start index of substring (inclusive)endIndex - end index of substring (exclusive)public static String truncateString(String s, int maximumLength)
String.substring(int, int), doesn't break Unicode code
points. If the specified length in characters breaks a valid pair of
surrogates, the whole pair is not included into result.s - the string to truncatemaximumLength - the maximum length in characterspublic static String cache(String s)
s - the original stringpublic static void clearCache()
public static int parseUInt31(String s, int start, int end)
s - string to parsestart - the beginning index, inclusiveend - the ending index, exclusiveint not greater than Integer.MAX_VALUE.public static byte[] convertHexToBytes(String s)
s - the hex encoded stringpublic static ByteArrayOutputStream convertHexWithSpacesToBytes(ByteArrayOutputStream baos, String s, int start, int end)
baos - the output stream, or nulls - the hex encoded stringstart - the start indexend - the end index, exclusivepublic static String convertBytesToHex(byte[] value)
value - the byte arraypublic static String convertBytesToHex(byte[] value, int len)
value - the byte arraylen - the number of bytes to encodepublic static StringBuilder convertBytesToHex(StringBuilder builder, byte[] value)
builder - string builder to append tovalue - the byte arraypublic static StringBuilder convertBytesToHex(StringBuilder builder, byte[] value, int len)
builder - string builder to append tovalue - the byte arraylen - the number of bytes to encodepublic static StringBuilder appendHex(StringBuilder builder, long x, int bytes)
builder - string builder to append tox - value to appendbytes - number of bytes to appendpublic static boolean isNumber(String s)
s - the stringpublic static boolean isWhitespaceOrEmpty(String s)
s - the stringpublic static StringBuilder appendTwoDigits(StringBuilder builder, int positiveValue)
builder - the string builderpositiveValue - the number to appendpublic static StringBuilder appendZeroPadded(StringBuilder builder, int length, long positiveValue)
builder - the string builderlength - the number of characters to appendpositiveValue - the number to appendCopyright © 2022. All rights reserved.