Some friends may dynamically modify the value in the strings. xml file in Android. Here we recommend a simple method.
Nodes in strings. xml support placeholders, as shown below:
<String name = "data"> INTEGER: % 1 $ d, floating point: % 2 $. 2f, string: % 3 $ s </string>
Here, % is followed by the placeholder position, starting from 1,
$ Fill Data Type
% D: Integer type;
% F: indicates the floating point type. The. 2 In front of f indicates the decimal point.
% S: String
These are very similar to the placeholders of input and output functions in C.
In the program, we can use the following code to format the string, that is, to fill in the content in the placeholder:
String data = getResources (). getString (R. string. data );
Data = String. format (data, 100, 10.3 ");
The final running result is as follows:
Integer: 100, floating point: 10.30, string: 2011-07-01