public class Sprintf
extends java.lang.Object
Constructor and Description |
---|
Sprintf() |
Modifier and Type | Method and Description |
---|---|
static void |
formatChar(CharBuffer cb,
long ch,
int width,
int flags) |
static void |
formatDouble(CharBuffer cb,
double value,
int prec,
int flags,
int type) |
static void |
formatDouble(CharBuffer cb,
double value,
int width,
int prec,
int flags,
int type) |
static void |
formatInteger(CharBuffer cb,
double dvalue,
int width,
int prec,
int flags,
int radix) |
static void |
formatInteger(CharBuffer cb,
long dvalue,
int width,
int prec,
int flags,
int radix) |
static void |
formatString(CharBuffer cb,
java.lang.String string,
int prec,
int width,
int flags) |
static CharBuffer |
sprintf(CharBuffer result,
java.lang.String format,
java.lang.Object... args) |
static java.lang.String |
sprintf(java.lang.String format,
java.lang.Object arg0) |
static java.lang.String |
sprintf(java.lang.String format,
java.lang.Object[] args)
An implementation of the classic sprintf.
|
static java.lang.String |
sprintf(java.lang.String format,
java.lang.Object arg0,
java.lang.Object arg1) |
static java.lang.String |
sprintf(java.lang.String format,
java.lang.Object arg0,
java.lang.Object arg1,
java.lang.Object arg2) |
static java.lang.String |
sprintf(java.lang.String format,
java.lang.Object arg0,
java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3) |
static java.lang.String |
sprintf(java.lang.String format,
java.lang.Object arg0,
java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3,
java.lang.Object arg4) |
static java.lang.String |
sprintf(java.lang.String format,
java.lang.Object arg0,
java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3,
java.lang.Object arg4,
java.lang.Object arg5) |
static java.lang.String |
sprintf(java.lang.String format,
java.lang.Object arg0,
java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3,
java.lang.Object arg4,
java.lang.Object arg5,
java.lang.Object arg6) |
static java.lang.String |
sprintf(java.lang.String format,
java.lang.Object arg0,
java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3,
java.lang.Object arg4,
java.lang.Object arg5,
java.lang.Object arg6,
java.lang.Object arg7) |
static java.lang.String |
sprintf(java.lang.String format,
java.lang.Object arg0,
java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3,
java.lang.Object arg4,
java.lang.Object arg5,
java.lang.Object arg6,
java.lang.Object arg7,
java.lang.Object arg8) |
static java.lang.String |
sprintf(java.lang.String format,
java.lang.Object arg0,
java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3,
java.lang.Object arg4,
java.lang.Object arg5,
java.lang.Object arg6,
java.lang.Object arg7,
java.lang.Object arg8,
java.lang.Object arg9) |
static double |
toDouble(java.lang.Object value)
Converts some unknown value to a double.
|
static long |
toLong(java.lang.Object value)
Converts some unknown value to a long.
|
static java.lang.String |
toString(java.lang.Object value,
java.lang.String nullValue)
Converts some unknown value to a String.
|
public static java.lang.String sprintf(java.lang.String format, java.lang.Object[] args)
`sprintf' accepts a series of arguments, applies to each a format specifier from `format', and returns the formatted data as a string. `format' is a string containing two types of objects: ordinary characters (other than `%'), which are copied unchanged to the output, and conversion specifications, each of which is introduced by `%'. (To include `%' in the output, use `%%' in the format string).
A conversion specification has the following form:
%[FLAGS][WIDTH][.PREC][TYPE]TYPE is required, the rest are optional. The following TYPE's are supported:
%% | a percent sign |
%c | a character with the given number |
%s | a string, a null string becomes "#null" |
%z | a string, a null string becomes the empty string "" |
%d | a signed integer, in decimal |
%o | an integer, in octal |
%u | an integer, in decimal |
%x | an integer, in hexadecimal |
%X | an integer, in hexadecimal using upper-case letters |
%e | a floating-point number, in scientific notation |
%E | a floating-point number, like %e with an upper-case "E" |
%f | a floating-point number, in fixed decimal notation |
%g | a floating-point number, in %e or %f notation |
%G | a floating-point number, like %g with an upper-case "E" |
%p | a pointer (outputs a value like the default of toString()) |
The following optional FLAGS are supported:
0 | If the TYPE character is an integer leading zeroes are used to pad the field width instead of spaces (following any indication of sign or base). |
+ | Include a `+' with positive numbers. |
(a space) | use a space placeholder for the `+' that would result from a positive number |
- | The result of is left justified, and the right is padded with blanks until the result is `WIDTH' in length. If you do not use this flag, the result is right justified, and padded on the left. |
# | an alternate display is used, for `x' and `X' a non-zero result will have an "0x" prefix; for floating point numbers the result will always contain a decimal point. |
j | escape a string suitable for a Java string, or a CSV file. The following escapes are applied: " becomes \", newline becomes \n, return becomes \r, \ becomes \\. |
v | escape a string suitable for CSV files, the same as `j'
with an additional " placed at the beginning
and ending of the string
|
m | escape a string suitable for a XML file. The following escapes are applied: < becomes <, > becomes > & becomes & ' becomes ', " becomes &034; |
The optional PREC argument is introduced with a `.', and gives the maximum number of characters to print; or the minimum number of digits to print for integer and hex values; or the maximum number of significant digits for `g' and `G'; or the number of digits to print after the decimal point for floating points.
public static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5, java.lang.Object arg6, java.lang.Object arg7, java.lang.Object arg8, java.lang.Object arg9)
public static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5, java.lang.Object arg6, java.lang.Object arg7, java.lang.Object arg8)
public static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5, java.lang.Object arg6, java.lang.Object arg7)
public static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5, java.lang.Object arg6)
public static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4, java.lang.Object arg5)
public static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4)
public static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
public static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2)
public static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0, java.lang.Object arg1)
public static java.lang.String sprintf(java.lang.String format, java.lang.Object arg0)
public static CharBuffer sprintf(CharBuffer result, java.lang.String format, java.lang.Object... args)
public static void formatDouble(CharBuffer cb, double value, int prec, int flags, int type)
public static void formatDouble(CharBuffer cb, double value, int width, int prec, int flags, int type)
public static void formatInteger(CharBuffer cb, long dvalue, int width, int prec, int flags, int radix)
public static void formatInteger(CharBuffer cb, double dvalue, int width, int prec, int flags, int radix)
public static void formatChar(CharBuffer cb, long ch, int width, int flags)
public static void formatString(CharBuffer cb, java.lang.String string, int prec, int width, int flags)
public static double toDouble(java.lang.Object value)
value
- the value to be converted.public static long toLong(java.lang.Object value)
value
- the value to be converted.public static java.lang.String toString(java.lang.Object value, java.lang.String nullValue)
value
- the value to be converted.nullValue
- the value to return if value == null