First, let's look at the following code
protectedString calcu1 () {StringBuffer RESULTB=NewStringBuffer (); String Str=NULL; STR= String.Format ("hi,%s", "Wang Li"); Resultb.append (str+ "|"); STR= String.Format ("hi,%s:%s.%s", "Wang Nan", "Li Li", "Wang Zhang"); Resultb.append (str+ "|"); STR= String.Format (locale.us, "%" + 3 + "." + 4 + "G", 136985021.96584239551); Resultb.append (str+ "|"); SimpleDateFormat format=NULL; if(Iszh ( This) ) {format=NewSimpleDateFormat ("yyyy mm month DD Day"); } Else{format=NewSimpleDateFormat ("Yyy-mm-dd"); } STR= Format.format (NewDate (1000000000*2000l)); Resultb.append (str+ "|"); STR=getresources (). getString (R.string.test); STR= String.Format (str, "yy")); Resultb.append (str+ "|"); STR=getresources (). getString (R.string.test1); STR= String.Format (str, "Henan", "Xiayi", 33); Resultb.append (str+ "|"); STR=resultb.tostring (); returnstr; }
The resource files are as follows
<?XML version= "1.0" encoding= "Utf-8"?><Resources> <stringname= "Test">My name is: \ "%1$s\"</string> <stringname= "Test1">I come from: \ "%1$s\" province, \ "%2$s\" county, this year \ "%3$d\" years old</string></Resources>
The results of the operation are as follows
The above is actually mainly related to the following two points of knowledge
1) How to use formatted strings in XML
This method is also relatively simple, mainly when defining strings in XML, add the placeholder you want to change, the common placeholder class is the same as the rules in C language,
S: string
C: Character
D: Integer
F: Floating point number
In the form of%1 $ s
% placeholder
1$ the first one
s string
When used, it corresponds to the method String.Format (String,s1,s2,s3 .... The second third of ... Parameters
String-format Style Use