1. Integer. For example, "I am 23 years old this year". This 23 is an integer. This can be written in string. xml. <string name = "old"> I am % 1 $ d this year </string>.
[Java]View
Plaincopy
- String sageformat = getresources (). getstring (R. String. Old );
- String sfinalage = string. Format (sageformat, 23 );
Replace % 1 $ d with 23; % 1 $ D represents the replacement of the first integer in the entire name = "old. If a name contains two integer values to be replaced, the second value is % 2 $ D, and so on. For specific program replacement, see the string type below; 2. string type, for example, "My name is Li Si, and I am from the capital Beijing". Here, "Li Si" and "capital Beijing" must be replaced. You can write this in string. xml. <string name = "alert"> my name is % 1 $ s, and I am from % 2 $ S </string> in the program:
[Java]View
Plaincopy
- View sourceprint? 1 string sageformatstring sageformat1 = getresources (). getstring (R. String. Alert );
- String sfinal1 = string. Format (sageformat1, "Li Si", "capital Beijing ");
Here the two strings need to be replaced, which correspond in sequence according to the above program.
<Xliff: G> label introduction:
The property ID can be named as needed.
Attribute Value example
% N $ MS: indicates that the output is a string, and N indicates the number of parameters. The m value can be set with spaces before the output.
% N $ MD: indicates that the output is an integer, and N indicates the number of parameters. To set M, you can place a space before the output, or set it to 0 m, put M 0 before output
% N $ MF: indicates that the output is a floating point number, and N indicates the number of parameters. Setting the m value can control the number of decimal places. For example, when M = 2.2, the output format is 00.00.
You can also write it as follows:
% D (integer)
% F (floating point number)
% S (string)
Example:
1.
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources xmlns: xliff = "urn: Oasis: names: TC: xliff: Document: 1.2">
2.
<String name = "test_xliff"> Xiaohong, <xliff: G id = "XXX"> % d </xliff: G>, aged <xliff: g id = "yyy"> % S </xliff: G> grade! </String>
3.
String test = string. Format (getresources (). getstring (R. String. test_xliff), 7, "2 ");
Output:
Xiaohong is 7 years old. He is in the second grade of primary school!
Statement: This article from http://blog.csdn.net/wufen1103/article/details/7846691