It is the Argument Index. You can read the docs. I will try to explain the string from the tutorial for you:
String fmt = "%1$4s %2$10s %3$10s%n";
// format
cnsl.printft(fmt, "Items", "Quantity", "Price");
cnsl.printft(fmt, "-----", "-----", "-----");
cnsl.printft(fmt, "Tomato", "1 kg", "15");
cnsl.printft(fmt, "Potato", "5 kg", "50");
cnsl.printft(fmt, "Onion", "2 kg", "30");
cnsl.printft(fmt, "Apple", "4 kg", "80");
In general the format is %[argument_index$][flags][width][.precision]conversion
.
In our example, #$
points to the position within our printft()
statement. We have 3 strings to be formatted and hence why our format string has 1$
, 2$
,3$
. The number that follows its the width between each argument. This width begins at 0 which means the actual width would be +1. The s
is our conversion to string and the %n
new line at the end.
Items Quantity Price
----- -------- -----
Tomato 1 kg 15
Potato 5 kg 50
Onion 2 kg 30
Apple 4 kg 80