我正在尝试找到有关在 java 中格式化字符串的完整教程。
我需要创建收据,如下所示:
HEADER IN MIDDLE '''''''''''''''''''''''''''''' Item1 Price Item2 x 5 Price Item3 that has a very long name.... Price '''''''''''''''''''''''''''''' Netprice: xxx Grossprice: xxx VAT: xxx Shipping cost: xxx Total: xxx '''''''''''''''''''''''''''''' FOOTER IN MIDDLE
最佳答案
传递给 string.format 的格式记录如下:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html#syntax
来自页面:
The format specifiers for general, character, and numeric types have the following syntax:
%[argument_index$][flags][width][.precision]conversion
The optional argument_index is a decimal integer indicating the position of the argument in the argument list. The first argument is referenced by "1$", the second by "2$", etc.
The optional flags is a set of characters that modify the output format. The set of valid flags depends on the conversion.
The optional width is a non-negative decimal integer indicating the minimum number of characters to be written to the output.
The optional precision is a non-negative decimal integer usually used to restrict the number of characters. The specific behavior depends on the conversion.
The required conversion is a character indicating how the argument should be formatted. The set of valid conversions for a given argument depends on the argument's data type.
关于java - 需要有关 String.format 的一些帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1588382/