String-related issues and notes in string. xml

Source: Internet
Author: User

String-related issues and notes in string. xml

1. If you need to display some strings with variables, such as "1st lesson? How can I help you write code? Section 2nd ", such a string can be defined in string. xml:

 
  
Lesson % 1 $ d ?? % 2 $ s ?? Section % 3 $ d

 

Each space must be replaced by an escape character. The code automatically prompts the escape character. Note that you need to use 1 2 3 to differentiate multiple variables.

Ii. Use StringUtil. java tool class:

/*** String tool class * Created by dwayon. */public class StringUtil {/*** convert to the corresponding String */public static String format (Context context, int formatId, Object... args) {String format = context. getString (formatId); return String. format (Locale. getDefault (), format, args );}}

Iii. Usage:

String section = StringUtil. format (context, R. string. section, 1, "teach you to write code", 2 );
In this way, you can get "1st class hours? How can I help you write code? Section 2nd "this is a string.

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.