public final class TextUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static char[] |
HEXADECIMAL_DIGITS
Set of digits suitable for encoding a number as a hexadecimal string.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
booleanFromString(java.lang.String s)
Convert a boolean string to a boolean value.
|
static byte[] |
bytesForHexadecimal(java.lang.String hexString)
Takes a string of hexadecimal-encoded byte values and converts it
back to an array of bytes.
|
static java.lang.String |
centerString(java.lang.String s,
int width)
Center a string in a fixed-width field, using blanks for padding.
|
static java.lang.String |
centerString(java.lang.String s,
int width,
char c)
Center a string in a fixed-width field, using the specified
character for padding.
|
static java.lang.String |
charToUnicodeEscape(char c)
Convert a character to its corresponding Unicode escape sequence.
|
static java.lang.String |
charToUnicodeEscape(char c,
java.lang.StringBuilder buf)
Convert a character to its corresponding Unicode escape sequence.
|
static java.lang.StringBuilder |
encodeNumber(int num,
int base,
char[] digits,
java.lang.StringBuilder buf)
Encode an integer in an arbitrary base; the caller specifies an
array of digit characters to be used for the encoding.
|
static java.lang.StringBuilder |
encodeNumber(long num,
int base,
char[] digits,
java.lang.StringBuilder buf)
Encode a long integer in an arbitrary base; the caller specifies
an array of digit characters to be used for the encoding.
|
static java.lang.StringBuilder |
encodeNumber(short num,
int base,
char[] digits,
java.lang.StringBuilder buf)
Encode a short integer in an arbitrary base; the caller specifies
an array of digit characters to be used for the encoding.
|
static java.lang.StringBuilder |
hexadecimalForByte(byte b,
java.lang.StringBuilder buf)
Encode a byte as a two-digit hexadecimal string, appending the
result to a StringBuilder.
|
static java.lang.StringBuilder |
hexadecimalForByte(int b,
java.lang.StringBuilder buf)
Encode a byte as a two-digit hexadecimal string, appending the
result to a StringBuilder.The hexadecimal string uses
lower-case digits.
|
static java.lang.String |
hexadecimalForBytes(byte[] bytes)
Encode an array of bytes as a hexadecimal string, returning the
string.
|
static java.lang.StringBuilder |
hexadecimalForBytes(byte[] bytes,
int start,
int end,
java.lang.StringBuilder buf)
Encode an array of bytes as a hexadecimal string, appending the
result to a StringBuilder.
|
static java.lang.StringBuilder |
hexadecimalForBytes(int[] bytes,
int start,
int end,
java.lang.StringBuilder buf)
Encode an array of bytes as a hexadecimal string, appending the
result to a StringBuilder.
|
static java.lang.String |
hexadecimalForNumber(int num)
Encode an integer as a hexadecimal string, returning the hex string.
|
static java.lang.StringBuilder |
hexadecimalForNumber(int num,
java.lang.StringBuilder buf)
Encode an integer as a hexadecimal string, appending the result
to a StringBuilder.
|
static java.lang.String |
hexadecimalForNumber(long num)
Encode a long as a hexadecimal string, returning the hex string.
|
static java.lang.StringBuilder |
hexadecimalForNumber(long num,
java.lang.StringBuilder buf)
Encode a long as a hexadecimal string, appending the result
to a StringBuilder.
|
static java.lang.String |
hexadecimalForNumber(short num)
Encode a short as a hexadecimal string, returning the hex string.
|
static java.lang.StringBuilder |
hexadecimalForNumber(short num,
java.lang.StringBuilder buf)
Encode a short as a hexadecimal string, appending the result
to a StringBuilder.
|
static boolean |
isPrintable(char c)
Determine whether a character is printable.
|
static java.lang.String |
join(char delim,
java.lang.String... strings)
Join a set of strings into one string, putting the specified delimiter
between adjacent strings.
|
static java.lang.String |
join(java.util.Collection<? extends java.lang.Object> objects,
char delim)
Join a set of strings into one string, putting the specified delimiter
between adjacent strings.
|
static java.lang.String |
join(java.util.Collection<? extends java.lang.Object> objects,
java.lang.String delim)
Join a set of strings into one string, putting the specified delimiter
between adjacent strings.
|
static java.lang.String |
join(java.lang.String[] strings,
char delim)
Join an array of strings into one string, putting the specified
delimiter between adjacent strings.
|
static java.lang.String |
join(java.lang.String[] strings,
int start,
int end,
char delim)
Join an array of strings into one string, putting the specified
delimiter between adjacent strings, starting at a specified index.
|
static java.lang.String |
join(java.lang.String[] strings,
int start,
int end,
java.lang.String delim)
Join an array of strings into one string, putting the specified
delimiter between adjacent strings, starting at a specified index.
|
static java.lang.String |
join(java.lang.String[] strings,
java.lang.String delim)
Join a set of strings into one string, putting the specified delimiter
between adjacent strings.
|
static java.lang.String |
join(java.lang.String delim,
java.lang.String... strings)
Join a set of strings into one string, putting the specified delimiter
between adjacent strings.
|
static java.lang.String |
leftJustifyString(java.lang.String s,
int width)
Left justify a string in a fixed-width field, using blanks for
padding.
|
static java.lang.String |
leftJustifyString(java.lang.String s,
int width,
char c)
Left justify a string in a fixed-width field, using the specified
character for padding.
|
static java.lang.String |
rightJustifyString(java.lang.String s,
int width)
Right justify a string in a fixed-width field, using blanks for
padding.
|
static java.lang.String |
rightJustifyString(java.lang.String s,
int width,
char c)
Right justify a string in a fixed-width field, using the specified
character for padding.
|
static java.lang.String |
romanNumeralsForNumber(int n)
Get the (upper-case) Roman numeral string for a number.
|
static java.lang.String[] |
split(java.lang.String s)
Split a string on white space, into one or more strings.
|
static java.lang.String[] |
split(java.lang.String s,
boolean preserveEmptyFields)
Split a string on white space, into one or more strings.
|
static java.lang.String[] |
split(java.lang.String s,
char delim)
Split a string into one or more strings, based on a delimiter.
|
static java.lang.String[] |
split(java.lang.String s,
char delim,
boolean preserveEmptyFields)
Split a string into one or more strings, based on a delimiter.
|
static int |
split(java.lang.String s,
char delim,
java.util.Collection<java.lang.String> collection)
Split a string into one or more strings, based on a delimiter.
|
static int |
split(java.lang.String s,
char delim,
java.util.Collection<java.lang.String> collection,
boolean preserveEmptyFields)
Split a string into one or more strings, based on a delimiter.
|
static int |
split(java.lang.String s,
java.util.Collection<java.lang.String> collection)
Split a string on white space, into one or more strings.
|
static int |
split(java.lang.String s,
java.util.Collection<java.lang.String> collection,
boolean preserveEmptyFields)
Split a string on white space, into one or more strings.
|
static java.lang.String[] |
split(java.lang.String s,
java.lang.String delimSet)
Split a string into one or more strings, based on a set of
delimiter.
|
static java.lang.String[] |
split(java.lang.String s,
java.lang.String delimSet,
boolean preserveEmptyFields)
Split a string into one or more strings, based on a set of
delimiter.
|
static int |
split(java.lang.String s,
java.lang.String delimSet,
java.util.Collection<java.lang.String> collection)
Split a string into one or more strings, based on a set of
delimiter.
|
static int |
split(java.lang.String s,
java.lang.String delimSet,
java.util.Collection<java.lang.String> collection,
boolean preserveEmptyFields)
Split a string into one or more strings, based on a set of
delimiter.
|
static boolean |
stringIsEmpty(java.lang.String s)
Determine whether a given string is empty.
|
public static final char[] HEXADECIMAL_DIGITS
hexadecimalForNumber(int,StringBuilder)
,
hexadecimalForNumber(short,StringBuilder)
,
hexadecimalForNumber(long,StringBuilder)
,
hexadecimalForByte(byte,StringBuilder)
,
hexadecimalForByte(int,StringBuilder)
,
hexadecimalForBytes(byte[],int,int,StringBuilder)
,
hexadecimalForBytes(int[],int,int,StringBuilder)
,
encodeNumber(long,int,char[],StringBuilder)
,
encodeNumber(int,int,char[],StringBuilder)
,
encodeNumber(short,int,char[],StringBuilder)
public static boolean booleanFromString(java.lang.String s) throws java.lang.IllegalArgumentException
s
- string to convertjava.lang.IllegalArgumentException
- string isn't a booleanpublic static java.lang.String[] split(java.lang.String s)
Split a string on white space, into one or more strings. This
method is intended to be reminiscent of the corresponding perl or
awk split() function, though without regular expression
support. This version of split() does not preserve
empty strings. That is, the string "a:b::c", when split with a
":" delimiter, yields three fields ("a", "b", "c"), since the
two adjacent ":" characters are treated as one delimiter. To
preserve empty strings, pass true as the
preserveEmptyFields parameter to the
split(String,boolean)
method.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
s
- the string to splitsplit(String,boolean)
,
split(String,String)
,
split(String,char)
,
split(String,Collection)
,
split(String,char,Collection)
,
split(String,String,Collection)
public static java.lang.String[] split(java.lang.String s, boolean preserveEmptyFields)
Split a string on white space, into one or more strings. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
s
- the string to splitpreserveEmptyFields
- Whether to parse through empty tokens or
preserve them. For example, given the string
string "a:b::c" and a delimiter of ":",
if preserveEmptyStrings is
true, then this method will return
four strings, "a", "b", "", "c". If
preserveEmptyStrings is
false, then this method will return
three strings, "a", "b", "c" (since the
two adjacent ":" characters are treated as
one delimiter.)split(String)
,
split(String,String)
,
split(String,char)
,
split(String,Collection)
,
split(String,char,Collection)
,
split(String,String,Collection)
public static int split(java.lang.String s, java.util.Collection<java.lang.String> collection)
Split a string on white space, into one or more strings. This
method is intended to be reminiscent of the corresponding perl or
awk split() function, though without regular expression
support. This version of split() does not preserve
empty strings. That is, the string "a:b::c", when split with a
":" delimiter, yields three fields ("a", "b", "c"), since the
two adjacent ":" characters are treated as one delimiter. To
preserve empty strings, pass true as the
preserveEmptyFields parameter to the
split(String,Collection,boolean)
method.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
s
- the string to splitcollection
- where to store the split stringssplit(String,Collection,boolean)
,
split(String)
,
split(String,String)
,
split(String,char)
,
split(String,char,Collection)
,
split(String,String,Collection)
public static int split(java.lang.String s, java.util.Collection<java.lang.String> collection, boolean preserveEmptyFields)
Split a string on white space, into one or more strings. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
s
- the string to splitcollection
- where to store the split stringspreserveEmptyFields
- Whether to parse through empty tokens or
preserve them. For example, given the string
string "a:b::c" and a delimiter of ":",
if preserveEmptyStrings is
true, then this method will return
four strings, "a", "b", "", "c". If
preserveEmptyStrings is
false, then this method will return
three strings, "a", "b", "c" (since the
two adjacent ":" characters are treated as
one delimiter.)split(String,Collection)
,
split(String)
,
split(String,String)
,
split(String,char)
,
split(String,char,Collection)
,
split(String,String,Collection)
public static java.lang.String[] split(java.lang.String s, char delim)
Split a string into one or more strings, based on a delimiter.
This method is intended to be reminiscent of the corresponding perl
or awk split() function, though without regular expression
support. This version of split() does not preserve empty
strings. That is, the string "a:b::c", when split with a ":"
delimiter, yields three fields ("a", "b", "c"), since the two
adjacent ":" characters are treated as one delimiter. To preserve
empty strings, pass true as the
preserveEmptyFields parameter to the
split(String,char,boolean)
method.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
s
- the string to splitdelim
- the delimitersplit(String,char,boolean)
,
split(String)
,
split(String,String)
,
split(String,Collection)
,
split(String,char,Collection)
,
split(String,String,Collection)
public static java.lang.String[] split(java.lang.String s, char delim, boolean preserveEmptyFields)
Split a string into one or more strings, based on a delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
s
- the string to splitdelim
- the delimiterpreserveEmptyFields
- Whether to parse through empty tokens or
preserve them. For example, given the string
string "a:b::c" and a delimiter of ":",
if preserveEmptyStrings is
true, then this method will return
four strings, "a", "b", "", "c". If
preserveEmptyStrings is
false, then this method will return
three strings, "a", "b", "c" (since the
two adjacent ":" characters are treated as
one delimiter.)split(String,char)
,
split(String)
,
split(String,String)
,
split(String,Collection)
,
split(String,char,Collection)
,
split(String,String,Collection)
public static java.lang.String[] split(java.lang.String s, java.lang.String delimSet)
Split a string into one or more strings, based on a set of
delimiter. This method is intended to be reminiscent of the
corresponding perl or awk split() function, though without
regular expression support. This version of split() does
not preserve empty strings. That is, the string "a:b::c", when split
with a ":" delimiter, yields three fields ("a", "b", "c"), since the
two adjacent ":" characters are treated as one delimiter. To
preserve empty strings, pass true as the
preserveEmptyFields parameter to the
split(String,String,boolean)
method.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
s
- the string to splitdelimSet
- set of delimiters, or null to use white spacesplit(String,String,boolean)
,
split(String)
,
split(String,char)
,
split(String,Collection)
,
split(String,char,Collection)
,
split(String,String,Collection)
public static java.lang.String[] split(java.lang.String s, java.lang.String delimSet, boolean preserveEmptyFields)
Split a string into one or more strings, based on a set of delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
s
- the string to splitdelimSet
- set of delimiters, or null to use white spacepreserveEmptyFields
- Whether to parse through empty tokens or
preserve them. For example, given the string
string "a:b::c" and a delimiter of ":",
if preserveEmptyStrings is
true, then this method will return
four strings, "a", "b", "", "c". If
preserveEmptyStrings is
false, then this method will return
three strings, "a", "b", "c" (since the
two adjacent ":" characters are treated as
one delimiter.)split(String,String)
,
split(String)
,
split(String,char)
,
split(String,Collection)
,
split(String,char,Collection)
,
split(String,String,Collection)
public static int split(java.lang.String s, char delim, java.util.Collection<java.lang.String> collection)
Split a string into one or more strings, based on a delimiter.
This method is intended to be reminiscent of the corresponding perl
or awk split() function, though without regular expression
support. This version of split() does not preserve empty
strings. That is, the string "a:b::c", when split with a ":"
delimiter, yields three fields ("a", "b", "c"), since the two
adjacent ":" characters are treated as one delimiter. To preserve
empty strings, pass true as the
preserveEmptyFields parameter to the
split(String,char,Collection,boolean)
method.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
s
- the string to splitdelim
- the delimitercollection
- where to store the split stringssplit(String,char,Collection,boolean)
,
split(String)
,
split(String,char)
,
split(String,Collection)
,
split(String,String)
,
split(String,String,Collection)
public static int split(java.lang.String s, char delim, java.util.Collection<java.lang.String> collection, boolean preserveEmptyFields)
Split a string into one or more strings, based on a delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.
Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.
s
- the string to splitdelim
- the delimitercollection
- where to store the split stringspreserveEmptyFields
- Whether to parse through empty tokens or
preserve them. For example, given the string
string "a:b::c" and a delimiter of ":",
if preserveEmptyStrings is
true, then this method will return
four strings, "a", "b", "", "c". If
preserveEmptyStrings is
false, then this method will return
three strings, "a", "b", "c" (since the
two adjacent ":" characters are treated as
one delimiter.)split(String,char,Collection)
,
split(String)
,
split(String,char)
,
split(String,Collection)
,
split(String,String)
,
split(String,String,Collection)
public static int split(java.lang.String s, java.lang.String delimSet, java.util.Collection<java.lang.String> collection)
Split a string into one or more strings, based on a set of
delimiter. This method is intended to be reminiscent of the
corresponding perl or awk split() function, though without
regular expression support. This version of split() does
not preserve empty strings. That is, the string "a:b::c", when split
with a ":" delimiter, yields three fields ("a", "b", "c"), since the
two adjacent ":" characters are treated as one delimiter. To
preserve empty strings, pass true as the
preserveEmptyFields parameter to the
split(String,String,Collection,boolean)
method.
Note that the 1.4 JDK introduces a regular expression-based
split() method in the java.lang.String class. This
method does not use regular expressions. This version of
split() does not preserve empty strings. That is, the
string "a:b::c", when split with a ":" delimiter, yields three
fields ("a", "b", "c"), since the two adjacent ":" characters are
treated as one delimiter. To preserve empty strings, pass
true as the preserveEmptyFields parameter to the
split(String,String,Collection,boolean)
method.
s
- the string to splitdelimSet
- set of delimiterscollection
- where to store the split stringssplit(String,String,Collection,boolean)
,
split(String)
,
split(String,char)
,
split(String,Collection)
,
split(String,String)
,
split(String,char,Collection)
public static int split(java.lang.String s, java.lang.String delimSet, java.util.Collection<java.lang.String> collection, boolean preserveEmptyFields)
Split a string into one or more strings, based on a set of delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This method uses a StringTokenizer to do the actual work.
Note that the 1.4 JDK introduces a regular expression-based
split() method in the java.lang.String class. This
method does not use regular expressions. This version of
split() does not preserve empty strings. That is, the
string "a:b::c", when split with a ":" delimiter, yields three
fields ("a", "b", "c"), since the two adjacent ":" characters are
treated as one delimiter. To preserve empty strings, pass
true as the preserveEmptyFields parameter to the
split(String,String,Collection,boolean)
method.
s
- the string to splitdelimSet
- set of delimiterscollection
- where to store the split stringspreserveEmptyFields
- Whether to parse through empty tokens or
preserve them. For example, given the string
string "a:b::c" and a delimiter of ":",
if preserveEmptyStrings is
true, then this method will return
four strings, "a", "b", "", "c". If
preserveEmptyStrings is
false, then this method will return
three strings, "a", "b", "c" (since the
two adjacent ":" characters are treated as
one delimiter.)split(String,String,Collection)
,
split(String)
,
split(String,char)
,
split(String,Collection)
,
split(String,String)
,
split(String,char,Collection)
public static java.lang.String join(java.lang.String[] strings, java.lang.String delim)
strings
- the strings to be joineddelim
- the delimiter stringsplit(String,String)
,
join(String[],char)
public static java.lang.String join(java.lang.String delim, java.lang.String... strings)
delim
- the delimiter stringstrings
- the strings to be joinedsplit(String,char)
,
join(String[],String)
public static java.lang.String join(java.lang.String[] strings, char delim)
strings
- the strings to be joineddelim
- the delimiter charactersplit(String,char)
,
join(String[],String)
public static java.lang.String join(java.lang.String[] strings, int start, int end, char delim)
strings
- the strings to be joinedstart
- starting indexend
- one past the ending indexdelim
- the delimiter characterjava.lang.ArrayIndexOutOfBoundsException
- bad value for start
or endsplit(String,char)
,
join(String[],String)
public static java.lang.String join(java.lang.String[] strings, int start, int end, java.lang.String delim)
strings
- the strings to be joinedstart
- starting indexend
- one past the ending indexdelim
- the delimiter stringjava.lang.ArrayIndexOutOfBoundsException
- bad value for start
or endsplit(String,char)
,
join(String[],String)
public static java.lang.String join(char delim, java.lang.String... strings)
delim
- the delimiter characterstrings
- the strings to be joinedsplit(String,char)
,
join(String[],String)
public static java.lang.String join(java.util.Collection<? extends java.lang.Object> objects, java.lang.String delim)
objects
- A collection the items to be joined. This collection
can contain objects of any type; each object's
toString() method is called to produce the
string to be joined.delim
- the delimiter stringsplit(String,String,Collection)
,
join(Collection,char)
public static java.lang.String join(java.util.Collection<? extends java.lang.Object> objects, char delim)
objects
- A collection the items to be joined. This collection
can contain objects of any type; each object's
toString() method is called to produce the
string to be joined.delim
- the delimiter charactersplit(String,char,Collection)
,
join(Collection,String)
public static boolean stringIsEmpty(java.lang.String s)
s
- the string to testpublic static java.lang.String rightJustifyString(java.lang.String s, int width)
s
- the stringwidth
- the desired field widthrightJustifyString(String,int,char)
,
leftJustifyString(String,int)
,
centerString(String,int)
public static java.lang.String rightJustifyString(java.lang.String s, int width, char c)
s
- the stringwidth
- the desired field widthc
- the pad characterrightJustifyString(String,int)
,
leftJustifyString(String,int,char)
,
centerString(String,int,char)
public static java.lang.String leftJustifyString(java.lang.String s, int width)
s
- the stringwidth
- the desired field widthleftJustifyString(String,int,char)
,
rightJustifyString(String,int)
,
centerString(String,int)
public static java.lang.String leftJustifyString(java.lang.String s, int width, char c)
s
- the stringwidth
- the desired field widthc
- the pad characterleftJustifyString(String,int)
,
rightJustifyString(String,int,char)
,
centerString(String,int,char)
public static java.lang.String centerString(java.lang.String s, int width)
s
- the stringwidth
- the desired field widthcenterString(String,int,char)
,
rightJustifyString(String,int)
,
leftJustifyString(String,int)
public static java.lang.String centerString(java.lang.String s, int width, char c)
s
- the stringwidth
- the desired field widthc
- the pad charactercenterString(String,int,char)
,
leftJustifyString(String,int,char)
,
rightJustifyString(String,int,char)
public static java.lang.StringBuilder hexadecimalForByte(byte b, java.lang.StringBuilder buf)
hexadecimalForByte(int,StringBuilder)
if you want to pass an
unsigned byte value.b
- the bytebuf
- the StringBuilder to which to append the hex stringhexadecimalForByte(int,StringBuilder)
,
hexadecimalForBytes(byte[],int,int,StringBuilder)
,
hexadecimalForBytes(int[],int,int,StringBuilder)
,
bytesForHexadecimal(String)
public static java.lang.StringBuilder hexadecimalForByte(int b, java.lang.StringBuilder buf)
b
- the bytebuf
- the StringBuilder to which to append the hex stringhexadecimalForByte(byte,StringBuilder)
,
hexadecimalForBytes(byte[],int,int,StringBuilder)
,
hexadecimalForBytes(int[],int,int,StringBuilder)
,
bytesForHexadecimal(String)
public static java.lang.StringBuilder hexadecimalForBytes(byte[] bytes, int start, int end, java.lang.StringBuilder buf)
hexadecimalForBytes(int[],int,int,StringBuilder)
if you want to pass signed byte values.bytes
- The array of bytesstart
- starting index in byte arrayend
- one past ending index in byte array (thus,
bytes.length is a valid value)buf
- Where to append the resulthexadecimalForByte(byte,StringBuilder)
,
hexadecimalForByte(int,StringBuilder)
,
bytesForHexadecimal(String)
public static java.lang.String hexadecimalForBytes(byte[] bytes)
hexadecimalForBytes(buf, 0, buf.length, new StringBuilder()).toString()
bytes
- The array of byteshexadecimalForBytes(byte[],int,int,StringBuilder)
public static java.lang.StringBuilder hexadecimalForBytes(int[] bytes, int start, int end, java.lang.StringBuilder buf)
hexadecimalForBytes(byte[],int,int,StringBuilder)
if
you want to pass signed byte values.bytes
- The array of bytesstart
- starting index in byte arrayend
- one past ending index in byte array (thus,
bytes.length is a valid value)buf
- Where to append the resulthexadecimalForByte(byte,StringBuilder)
,
hexadecimalForByte(int,StringBuilder)
,
hexadecimalForBytes(byte[],int,int,StringBuilder)
,
bytesForHexadecimal(String)
public static java.lang.StringBuilder hexadecimalForNumber(int num, java.lang.StringBuilder buf)
num
- The integer to encodebuf
- Where to append the resultencodeNumber(int,int,char[],StringBuilder)
,
hexadecimalForNumber(short,StringBuilder)
,
hexadecimalForNumber(long,StringBuilder)
,
hexadecimalForByte(byte,StringBuilder)
,
hexadecimalForByte(int,StringBuilder)
,
hexadecimalForBytes(byte[],int,int,StringBuilder)
,
hexadecimalForBytes(int[],int,int,StringBuilder)
public static java.lang.String hexadecimalForNumber(int num)
num
- The integer to encodeencodeNumber(int,int,char[],StringBuilder)
,
hexadecimalForNumber(short)
,
hexadecimalForNumber(int,StringBuilder)
,
hexadecimalForNumber(long)
,
hexadecimalForByte(byte,StringBuilder)
,
hexadecimalForByte(int,StringBuilder)
,
hexadecimalForBytes(byte[],int,int,StringBuilder)
,
hexadecimalForBytes(int[],int,int,StringBuilder)
public static java.lang.StringBuilder hexadecimalForNumber(long num, java.lang.StringBuilder buf)
num
- The long to encodebuf
- Where to append the resultencodeNumber(long,int,char[],StringBuilder)
,
hexadecimalForNumber(int,StringBuilder)
,
hexadecimalForNumber(short,StringBuilder)
,
hexadecimalForNumber(long)
,
hexadecimalForByte(byte,StringBuilder)
,
hexadecimalForByte(int,StringBuilder)
,
hexadecimalForBytes(byte[],int,int,StringBuilder)
,
hexadecimalForBytes(int[],int,int,StringBuilder)
public static java.lang.String hexadecimalForNumber(long num)
num
- The long integer to encodeencodeNumber(int,int,char[],StringBuilder)
,
hexadecimalForNumber(short)
,
hexadecimalForNumber(long,StringBuilder)
,
hexadecimalForNumber(int)
,
hexadecimalForByte(byte,StringBuilder)
,
hexadecimalForByte(int,StringBuilder)
,
hexadecimalForBytes(byte[],int,int,StringBuilder)
,
hexadecimalForBytes(int[],int,int,StringBuilder)
public static java.lang.String hexadecimalForNumber(short num)
num
- The short integer to encodeencodeNumber(int,int,char[],StringBuilder)
,
hexadecimalForNumber(long)
,
hexadecimalForNumber(short,StringBuilder)
,
hexadecimalForNumber(int)
,
hexadecimalForByte(byte,StringBuilder)
,
hexadecimalForByte(int,StringBuilder)
,
hexadecimalForBytes(byte[],int,int,StringBuilder)
,
hexadecimalForBytes(int[],int,int,StringBuilder)
public static java.lang.StringBuilder hexadecimalForNumber(short num, java.lang.StringBuilder buf)
num
- The short integer to encodebuf
- Where to append the resulthexadecimalForNumber(int,StringBuilder)
,
hexadecimalForNumber(long,StringBuilder)
,
hexadecimalForNumber(short)
,
encodeNumber(short,int,char[],StringBuilder)
,
hexadecimalForByte(byte,StringBuilder)
,
hexadecimalForByte(int,StringBuilder)
,
hexadecimalForBytes(byte[],int,int,StringBuilder)
,
hexadecimalForBytes(int[],int,int,StringBuilder)
public static java.lang.StringBuilder encodeNumber(long num, int base, char[] digits, java.lang.StringBuilder buf)
Encode a long integer in an arbitrary base; the caller specifies an array of digit characters to be used for the encoding. For instance, to encode a number in base 36, you might use the following code fragment:
StringBuilder buf = new StringBuilder(); long num = ... char[] digits = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; TextUtils.encodeNumber (num, digits.length, digits, buf);
For convenience, this class provides a character array of
hexadecimal digits. (See HEXADECIMAL_DIGITS
.) However, it's
usually simpler just to use one of the hexadecimalForNumber()
methods().
num
- The long integer to encodebase
- The base in which to encode the numberdigits
- The array of digit characters to use for the encoding.
This array must be at least base characters
in length. digits[0] represents the numeral to
use for 0, digits[1] represents the numeral
to use for 1, etc.buf
- The StringBuilder to which to append the
encoded number stringencodeNumber(short,int,char[],StringBuilder)
,
encodeNumber(int,int,char[],StringBuilder)
,
hexadecimalForNumber(int,StringBuilder)
,
hexadecimalForNumber(short,StringBuilder)
,
hexadecimalForNumber(long,StringBuilder)
,
hexadecimalForByte(byte,StringBuilder)
,
hexadecimalForByte(int,StringBuilder)
,
hexadecimalForBytes(byte[],int,int,StringBuilder)
,
hexadecimalForBytes(int[],int,int,StringBuilder)
public static java.lang.StringBuilder encodeNumber(short num, int base, char[] digits, java.lang.StringBuilder buf)
Encode a short integer in an arbitrary base; the caller specifies an array of digit characters to be used for the encoding. For instance, to encode a number in base 36, you might use the following code fragment:
StringBuilder buf = new StringBuilder(); short num = ... char[] digits = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; TextUtils.encodeNumber (num, digits.length, digits, buf);
For convenience, this class provides a character array of
hexadecimal digits. (See HEXADECIMAL_DIGITS
.) However, it's
usually simpler just to use one of the hexadecimalForNumber()
methods().
num
- The short integer to encodebase
- The base in which to encode the numberdigits
- The array of digit characters to use for the encoding.
This array must be at least base characters
in length. digits[0] represents the numeral to
use for 0, digits[1] represents the numeral
to use for 1, etc.buf
- The StringBuilder to which to append the
encoded number stringencodeNumber(int,int,char[],StringBuilder)
,
encodeNumber(long,int,char[],StringBuilder)
,
hexadecimalForNumber(int,StringBuilder)
,
hexadecimalForNumber(short,StringBuilder)
,
hexadecimalForNumber(long,StringBuilder)
,
hexadecimalForByte(byte,StringBuilder)
,
hexadecimalForByte(int,StringBuilder)
,
hexadecimalForBytes(byte[],int,int,StringBuilder)
,
hexadecimalForBytes(int[],int,int,StringBuilder)
public static java.lang.StringBuilder encodeNumber(int num, int base, char[] digits, java.lang.StringBuilder buf)
Encode an integer in an arbitrary base; the caller specifies an array of digit characters to be used for the encoding. For instance, to encode a number in base 36, you might use the following code fragment:
StringBuilder buf = new StringBuilder(); int num = ... char[] digits = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; TextUtils.encodeNumber (num, digits.length, digits, buf);
For convenience, this class provides a character array of
hexadecimal digits. (See HEXADECIMAL_DIGITS
.)
However, it's usually simpler just to use one of the
hexadecimalForNumber() methods().
num
- The integer to encodebase
- The base in which to encode the numberdigits
- The array of digit characters to use for the encoding.
This array must be at least base characters
in length. digits[0] represents the numeral to
use for 0, digits[1] represents the numeral
to use for 1, etc.buf
- The StringBuilder to which to append the
encoded number stringencodeNumber(short,int,char[],StringBuilder)
,
encodeNumber(long,int,char[],StringBuilder)
,
hexadecimalForNumber(int,StringBuilder)
,
hexadecimalForNumber(short,StringBuilder)
,
hexadecimalForNumber(long,StringBuilder)
,
hexadecimalForByte(byte,StringBuilder)
,
hexadecimalForByte(int,StringBuilder)
,
hexadecimalForBytes(byte[],int,int,StringBuilder)
,
hexadecimalForBytes(int[],int,int,StringBuilder)
public static byte[] bytesForHexadecimal(java.lang.String hexString) throws java.lang.NumberFormatException
Takes a string of hexadecimal-encoded byte values and converts it back to an array of bytes. The string may or may not contain white space; all white space is stripped before parsing begins. However, white space cannot occur between the digits for a byte; it must only occur between bytes. That is, "6f a1" is legal, while "6 f a 1" is not. Each byte must be encoded as a 2-digits hexadecimal value; as a consequence, the input string must have an even number of characters, once all white space has been stripped. The hexadecimal digits "a" through "f" may be in upper- or lower-case. An illegal hexadecimal string will result in a NumberFormatException. The following strings are examples of legal input to this method:
1F 66756c6c74696c742e636f6d 42 72 69 61 6e 20 43 6c 61 70 70 65 72 49 2D41 63 63656C
The following strings are examples of illegal input:
1X 6 6f a 1 6675-6c6c-7469-6c742e-636f6d
hexString
- the hex string to convertjava.lang.NumberFormatException
- if the hex string is invalidhexadecimalForByte(byte,StringBuilder)
,
hexadecimalForByte(int,StringBuilder)
,
hexadecimalForBytes(byte[],int,int,StringBuilder)
,
hexadecimalForBytes(int[],int,int,StringBuilder)
public static java.lang.String romanNumeralsForNumber(int n)
n
- the number; must be positivepublic static java.lang.String charToUnicodeEscape(char c, java.lang.StringBuilder buf)
c
- the characterbuf
- where to store the resultcharToUnicodeEscape(char)
public static java.lang.String charToUnicodeEscape(char c)
c
- the charactercharToUnicodeEscape(char)
public static boolean isPrintable(char c)
Determine whether a character is printable. This method uses a simple definition of "printable" that doesn't take into account specific locales. A character is assumed to be printable if (a) it's in the Basic Latin, Latin 1 Supplement, or Extended Latin A Unicode block, and (b) its type, as returned by java.lang.Character.getType() is one of:
All other characters are assumed to be non-printable, even if they could actually be printed in the current locale or on some printer.
c
- the character to test