Modify the strings. xml file in Android

Source: Internet
Author: User

Some friends may dynamically modify the value in the strings. xml file in Android. Here we recommend a simple method.
Nodes in strings. XML support placeholders, as shown below:

<String name = "data"> INTEGER: % 1 $ D, floating point: % 2 $. 2f, string: % 3 $ S </string>

Here, % is followed by the placeholder position, starting from 1,

$ Fill Data Type
% D: Integer type;
% F: indicates the floating point type. The. 2 In front of F indicates the decimal point.
% C: String
These are very similar to the placeholders of input and output functions in C.

In the program, we can use the following code to format the string, that is, to fill in the content in the placeholder:

String data = getresources (). getstring (R. String. data); Data = string. Format (data, 100, 10.3, "2011-07-01 ");

The final running result is as follows:

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.