如何重复使用相同的字符串进行格式放置?例如
"%s-%s-%s" format("OK")
>> "OK-OK-OK"
最佳答案
这应该有效:
"%1$s-%1$s-%1$s" format "OK"
WrappedString的格式
方法在后台使用 java.util.Formatter
。还有 Formatter Javadoc说:
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.
关于java - 如何在 Scala 中以字符串格式重复参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13157584/