Android XML string wildcard

Source: Internet
Author: User

1. Basic Use Method
The following string is defined in the XML:
<string name= "Buff" >%1$d---%2$s</string>
Parsing in code:
String buf = getString (R.string.buff);
BUF = String.Format (buf, 222, "AA");

Description:%n represents the nth parameter passed by format, starting at 0, such as:%1 for the first, and%2 for 2nd.
%2 can be in front of%1, as defined below:
<string name= "Buff" >%2$s---%1$d</string>

2. Attribute values
%n$[m]s: Represents the output of a string, n is the number of parameters, setting the value of M can place a space before the output.
%n$[m]d: Represents the output of an integer, n is the number of arguments, the value of M indicates a minimum of multiple character bits, padding blanks when insufficient, can also be set to 0m, placed before the output m 0.
%n$[m.k]f: Represents the output of floating-point numbers, N is the number of parameters, the value of M indicates the minimum number of characters to occupy the entire floating-point numbers, when insufficient padding space before, K indicates the number of decimal places,
When set to 8.2, the number 5.02365894, the output format is 5.02, the number is 8 characters in total, 4 characters in front

3. Exceptions
For the specified attribute format, the corresponding type must be filled in, otherwise a illegalformatconversionexception exception will be thrown.

4. For%2$s and so on character best manual input, otherwise may appear correct statement, will report the following error
Error:multiple substitutions specified in non-positional format; Did you mean to add the formatted= "false" attribute?

Android XML string wildcard

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.