public class StringUtils extends Object
Modifier and Type | Method and Description |
---|---|
static String |
addAsterisk(String s,
int index)
Add an asterisk ('[*]') at the given position.
|
static void |
appendZeroPadded(StringBuilder buff,
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 byte[] |
convertHexToBytes(String s)
Convert a hex encoded string to a byte array.
|
static String |
enclose(String s)
Enclose a string with '(' and ')' if this is not yet done.
|
static boolean |
equals(String a,
String b)
Check if two strings are equal.
|
static String |
fromCacheOrNew(String s)
Get a string from the cache, and if no such string has been found, create
a new one with only this content.
|
static String |
indent(String s)
Indents a string with 4 spaces.
|
static String |
indent(String s,
int spaces,
boolean newline)
Indents a string with spaces.
|
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 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 String |
pad(String string,
int n,
String padding,
boolean right)
Pad a string.
|
static String |
quoteIdentifier(String s)
Enclose a string with double quotes.
|
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 |
quoteRemarkSQL(String sql)
In a string, replace block comment marks with /++ ..
|
static String |
quoteStringSQL(String s)
Convert a string to a SQL literal.
|
static String |
replaceAll(String s,
String before,
String after)
Replace all occurrences of the before string with the after string.
|
static boolean |
startsWithIgnoreCase(String s,
String start)
Check is a string starts with another string, ignoring the case.
|
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 String |
unEnclose(String s)
Remove enclosing '(' and ')' if this text is enclosed.
|
static String |
urlDecode(String encoded)
Decode the URL to a string.
|
static String |
urlEncode(String s)
Encode the string as an URL.
|
static String |
utf8Decode(byte[] utf8)
Convert a UTF-8 representation of a text to the text.
|
static byte[] |
utf8Encode(String s)
Convert the text to UTF-8 format.
|
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 |
xmlStartDoc()
Returns
|
static String |
xmlText(String text)
Escapes an XML text element.
|
public static boolean equals(String a, String b)
a
- the first valueb
- the second valuepublic static String toUpperEnglish(String s)
s
- the test to convertpublic static String toLowerEnglish(String s)
s
- the text to convertpublic static boolean startsWithIgnoreCase(String s, String start)
s
- the string to check (must be longer than start)start
- the prefix of spublic static String quoteStringSQL(String s)
s
- the text to convert.public static String javaEncode(String s)
s
- the text to convertpublic 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 byte[] utf8Encode(String s)
s
- the textpublic static String utf8Decode(byte[] utf8)
utf8
- the UTF-8 representationpublic static String quoteJavaStringArray(String[] array)
array
- the string arraypublic static String quoteJavaIntArray(int[] array)
array
- the int arraypublic static String enclose(String s)
s
- the stringpublic static String unEnclose(String s)
s
- the potentially enclosed stringpublic 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 indent(String s)
s
- the stringpublic static String indent(String s, int spaces, boolean newline)
s
- 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 replaceAll(String s, String before, String after)
s
- the stringbefore
- the old textafter
- the new textpublic static String quoteIdentifier(String s)
s
- the textpublic static boolean isNullOrEmpty(String s)
s
- the string to checkpublic static String quoteRemarkSQL(String sql)
sql
- the stringpublic 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 cache(String s)
s
- the original stringpublic static String fromCacheOrNew(String s)
s
- the stringpublic static void clearCache()
public static byte[] convertHexToBytes(String s)
s
- the hex encoded stringpublic 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 boolean isNumber(String s)
s
- the stringpublic static void appendZeroPadded(StringBuilder buff, int length, long positiveValue)
buff
- the string builderlength
- the number of characters to appendpositiveValue
- the number to appendCopyright © 2012 JBoss by Red Hat. All Rights Reserved.