gpt4 book ai didi

java - 需要有关 String.format 的一些帮助

转载 作者:行者123 更新时间:2023-12-01 16:41:40 25 4
gpt4 key购买 nike

我正在尝试找到有关在 java 中格式化字符串的完整教程。

我需要创建收据,如下所示:

       HEADER IN MIDDLE''''''''''''''''''''''''''''''Item1                   PriceItem2 x 5               PriceItem3 that has a verylong name....           Price''''''''''''''''''''''''''''''Netprice:                 xxxGrossprice:               xxxVAT:                      xxxShipping cost:            xxxTotal:                    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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com