|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.braju.format.BasicFormatString | +--com.braju.format.Format
This class provides static C-style methods like sprintf(), printf() and
fprintf() with variable number of parameters.
Format specification
This is the format of one conversion specification.
. __%__ _________ __ _________ __ ________________ __type__ . | | | | | | . |__flags__| |__width__| |__.__precision__|
or
% flag* [width] [.precision] type
flags Justification of output and printing of signs, blanks, decimal points, octal, and hexadecimal prefixes, and the semantics for wchar_t precision unit.
width Minimum number of characters (bytes) output.
precision Maximum number of characters (bytes) printed for all or part of the output field, or minimum number of digits printed for integer values.
Flag | Brief description |
- (minus sign) | Left adjusted, otherwise right adjusted. |
+ (plus sign) | Prefix the output value with a sign (+ or -) if the output value is of a signed type. Default is that sign appears only for negative values (-). |
' ' (blank) | A nonnegative value will have a space prepended. The + flag overrides the blank flag if both appear, and a positive value will be output with a sign. |
# (pound) | Alternative form. When used with the o, x, X, b or B formats, the # flag prefixes any output value with 0, 0x, 0X, 0b or 0B, respectively. When used with the f, e, or E formats, the # flag forces the output value to contain a decimal point in all cases. When used with the c format, the # flag forces the output value to be in UTF-encoding, e.g. A. |
0 (zero) | When used with the b, B, d, i, u, o, x, X, e, E, f, g, or G formats, the 0 flag causes leading 0's to pad the output to the field width. The 0 flag is ignored if the - flag is specified. |
Width | Brief description |
* (asterix) | The value for the precision will be obtained from the parameter list. If the value is negative the output will be left-justified. |
n (an integer) | A nonnegative integer for the width; e.g. 8. |
Precision | Brief description |
* (asterix) | The value for the width will be obtained from the parameter list. |
n (an integer) | A nonnegative integer for the precision; e.g. 3. |
Conversion
type |
Corresponding argument
will be printed as |
l,L1 | a logical value, i.e. a boolean values; e.g. true, FALSE. Also support for C-style booleans, i.e. 0 or 1 (<>0). |
c | a character. |
d, i | a decimal integer. |
u | an unsigned integer. This flag is applicable to the byte, the short and the int data types only. |
b1 | a binary integer. |
x,X | a hexadecimal integer. |
o | an octal integer. |
e,E | a scientific floating point number; e.g. 1.23E-03. |
f | a floating point number; e.g. 0.00123. |
g,G | %e or %E is used if the exponent is less than -4 or greater than or equal to the precision; otherwise %f is used. Trailing zeros are truncated, and the decimal point appears only if one or more digits follow it. |
s | a string. All characters in String is printed or as many as precision specifies. |
% | There is no corresponding argument, i.e. To output "%" one have to put "%%" in the format string. |
1 | Not an ANSI-C standard. |
Example:
Format.printf("Please, try to support %3.2f%% %s!\n", new Parameters(100).add("Java"));gives
Please, try to support 100.00% Java!You can also do like this
Parameters p = new Parameters(); Format.printf("Please, try to support %.2f%% %s!\n", p.add(100).add("Java")); Format.printf("Or, at least %.1f%%.\n", p.add(99.945));which gives
Please, try to support 100.00% Java! Or, at least too 99.9%.For more examples see the official Java printf site: www.braju.com.
Parameters
,
ParametersAutoClear
Method Summary | |
static void |
fprintf(java.io.OutputStream out,
java.lang.String fmt)
The format-string is passed to the stream. |
static void |
fprintf(java.io.OutputStream out,
java.lang.String fmt,
java.lang.Object[] params)
The parameters in Object[] are converted according to the format-string and then passed to the stream. |
static void |
fprintf(java.io.OutputStream out,
java.lang.String fmt,
Parameters params)
The parameters are converted according to the format-string and then passed to the stream. |
static void |
fprintf(java.io.OutputStream out,
java.lang.String fmt,
java.util.Vector params)
The parameters in the vector are converted according to the format-string and then passed to the stream. |
static void |
fprintf(java.io.Writer out,
java.lang.String fmt)
The format-string is passed to the writer [not supported in the Java 1.0.2 version]. |
static void |
fprintf(java.io.Writer out,
java.lang.String fmt,
java.lang.Object[] params)
The parameters in Object [] are converted according to the format-string and then passed to the writer [not supported in the Java 1.0.2 version]. |
static void |
fprintf(java.io.Writer out,
java.lang.String fmt,
Parameters params)
The parameters are converted according to the format-string and then passed to the writer [not supported in the Java 1.0.2 version]. |
static void |
fprintf(java.io.Writer out,
java.lang.String fmt,
java.util.Vector parameters)
The parameters in the vector are converted according to the format-string and then passed to the writer [not supported in the Java 1.0.2 version]. |
static boolean |
getModifyLineSeparators()
Return true if the Format-class replace all occurens of '\n' with the line separator of the local system, i.e. line.separator. |
static java.lang.String |
getVersion()
Gets the version as a string. |
static void |
main(java.lang.String[] args)
This is the command line version of Java printf. |
static void |
printf(java.lang.String fmt)
The format-string is printed to the standard output. |
static void |
printf(java.lang.String fmt,
java.lang.Object[] params)
The parameters in Object[] are converted according to the format-string and printed to the standard output. |
static void |
printf(java.lang.String fmt,
Parameters params)
The parameters are converted according to the format-string and printed to the standard output. |
static void |
printf(java.lang.String fmt,
java.util.Vector parameters)
The parameters in the vector are converted according to the format-string and printed to the standard output. |
static void |
setModifyLineSeparators(boolean status)
By setting the modifyLineSeparators property the Format-class will replace all occurens of '\n' with the line separator of the local system, i.e. |
static java.lang.String |
sprintf(java.lang.String fmt,
java.lang.Object[] params)
The parameters in Object[] are converted according to the format-string and then returned as a string. |
static java.lang.String |
sprintf(java.lang.String fmt,
Parameters parameters)
The parameters are converted according to the format-string and then returned as a string. |
static java.lang.String |
sprintf(java.lang.String fmt,
java.util.Vector parameters)
The parameters in the vector are converted according to the format-string and then returned as a string. |
static void |
version()
Print, on standard output, information about this class. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static void fprintf(java.io.OutputStream out, java.lang.String fmt) throws java.io.IOException, ParseErrorException
java.io.IOException
ParseErrorException
public static void fprintf(java.io.OutputStream out, java.lang.String fmt, java.lang.Object[] params) throws java.io.IOException, ParseErrorException
java.io.IOException
ParseErrorException
public static void fprintf(java.io.OutputStream out, java.lang.String fmt, Parameters params) throws java.io.IOException, ParseErrorException
java.io.IOException
ParseErrorException
public static void fprintf(java.io.OutputStream out, java.lang.String fmt, java.util.Vector params) throws java.io.IOException, ParseErrorException
java.io.IOException
ParseErrorException
public static void fprintf(java.io.Writer out, java.lang.String fmt) throws java.io.IOException, ParseErrorException
java.io.IOException
ParseErrorException
public static void fprintf(java.io.Writer out, java.lang.String fmt, java.lang.Object[] params) throws java.io.IOException, ParseErrorException
java.io.IOException
ParseErrorException
public static void fprintf(java.io.Writer out, java.lang.String fmt, Parameters params) throws java.io.IOException, ParseErrorException
java.io.IOException
ParseErrorException
public static void fprintf(java.io.Writer out, java.lang.String fmt, java.util.Vector parameters) throws java.io.IOException, ParseErrorException
java.io.IOException
ParseErrorException
public static boolean getModifyLineSeparators()
public static java.lang.String getVersion()
public static void main(java.lang.String[] args) throws java.lang.Exception
-help | Print this message. |
-printf | Using the next argument (fmtstr) as the format string and one or more optional parameters (param) as values to be formatted by the printf method. |
-version | Print version information. |
java.lang.Exception
public static void printf(java.lang.String fmt) throws ParseErrorException
ParseErrorException
public static void printf(java.lang.String fmt, java.lang.Object[] params) throws ParseErrorException
ParseErrorException
public static void printf(java.lang.String fmt, Parameters params) throws ParseErrorException
ParseErrorException
public static void printf(java.lang.String fmt, java.util.Vector parameters) throws ParseErrorException
ParseErrorException
public static void setModifyLineSeparators(boolean status)
public static java.lang.String sprintf(java.lang.String fmt, java.lang.Object[] params) throws ParseErrorException
ParseErrorException
public static java.lang.String sprintf(java.lang.String fmt, Parameters parameters) throws ParseErrorException
ParseErrorException
public static java.lang.String sprintf(java.lang.String fmt, java.util.Vector parameters) throws ParseErrorException
ParseErrorException
public static void version()
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |