Detailed explanation of Android String resource file insertion value instance
When we use string string resource file reference, we sometimes encounter the problem of inserting a value in the middle of a string.
For example, login name: XXX, here XXX is changing. At this time we may think of splicing. In fact, it can also be processed using formatting. for example
<string name="alert">I am %1$d years old</string>
If used in the code:
nt nAge=23; String sAgeFormat = getResources().getString(); String sFinalAge = (sAgeFormat, nAge);
When multiple parameters
<string name="alert2">My name is %1$s , I am form %2$s</string>
If used in the code:
String sInfoFormat = getResources().getString(.alert2); String sFinalInfo=(sInfoFormat, sName, sCity);
Thank you for reading, I hope it can help you. Thank you for your support for this site!