1. Basic Use Method
The following string is defined in the XML:
<string name= "Buff" >%1$d---%2$s</string>
Parsing in code:
String buf = getString (R.string.buff);
BUF = String.Format (buf, 222, "AA");
Description:%n represents the nth parameter passed by format, starting at 0, such as:%1 for the first, and%2 for 2nd.
%2 can be in front of%1, as defined below:
<string name= "Buff" >%2$s---%1$d</string>
2. Attribute values
%n$[m]s: Represents the output of a string, n is the number of parameters, setting the value of M can place a space before the output.
%n$[m]d: Represents the output of an integer, n is the number of arguments, the value of M indicates a minimum of multiple character bits, padding blanks when insufficient, can also be set to 0m, placed before the output m 0.
%n$[m.k]f: Represents the output of floating-point numbers, N is the number of parameters, the value of M indicates the minimum number of characters to occupy the entire floating-point numbers, when insufficient padding space before, K indicates the number of decimal places,
When set to 8.2, the number 5.02365894, the output format is 5.02, the number is 8 characters in total, 4 characters in front
3. Exceptions
For the specified attribute format, the corresponding type must be filled in, otherwise a illegalformatconversionexception exception will be thrown.
4. For%2$s and so on character best manual input, otherwise may appear correct statement, will report the following error
Error:multiple substitutions specified in non-positional format; Did you mean to add the formatted= "false" attribute?
Android XML string wildcard