%1 $ s%1$d android string (Java & android format string)
1$s//String
%1$D//INT
R.string.old:
<string name= "old" > I'm%1$d year OID. </string>
String Sageformat = Getresources (). getString (R.string.old);
String sfinalage = String.Format (Sageformat, 23);
1, integral type, such as "I am 23 years old", this 23 is integral type. It can be written in String.xml, <string name= "old" > I%1$d this year </string>
In the program, use the
String Sageformat = Getresources (). getString (R.string.old);
String sfinalage = String.Format (Sageformat, 23);
Replace the%1$d with 23;
%1$d expression means the whole name= "old", the first integer substitution. If there are two integral types in a name that need to be replaced, the second one is:%2$d, and so on; Replace the string type shown in the program;
2, String type, such as "My name is Dick, I come from the capital of Beijing", where the "dick" and "capital of Beijing" need to be replaced.
It can be written in String.xml, <string name= "alert" > My name is%1 $ s, I am from%2$s</string>
In the program:
String sageformatstring sageformat1= getresources (). getString (R.string.alert);
String SFinal1 = String.Format (SAGEFORMAT1, "Dick", "capital Beijing");
Here two strings need to be replaced, according to the order of the above program.
<xliff:g> Label Introduction:
Property IDs can be arbitrarily named
Attribute values illustrate
%n$ms: Represents the output is a string, n represents the first few parameters, set the value of M can be placed before the output space
%N$MD: On behalf of the output is an integer, n represents the first few parameters, set the value of M can be placed before the output space, can also be set to 0m, before the output placed M 0
%N$MF: Represents the output is a floating-point number, N represents the first few parameters, set the value of M can control decimal places, such as m=2.2, output format is 00.00
can also be simply written:
%d (representing integers)
%f (for floating point numbers)
%s (representing a string)
Use the steps for 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" > Xiao Hong this year <xliff:g id= "xxx" >%d</xliff:g> years old, on <xliff:g id= "yyy" >%s</ Xliff:g> Grade! </string>
3.
String test = String.Format (Getresources (). getString (R.string.test_xliff), 7, "primary Two");
Output:
Xiao Hong this year 7 years old, the second grade of primary school!
The above is the Java and Android output string data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!