Android strings. xml escape characters, pay attention to the details

Source: Internet
Author: User

XML escape characters
The numbers and string escape characters of the XML flag are as follows:
"(& #34; or & quot ;)
'(& #39; or & apos ;)
& (& #38; or & amp ;)
Lt (<) (& #60; or & lt ;)
Gt (>) (& #62; or & gt ;)

Example:
For example, the following string is defined in string. xml,
<String name = "first"> hello, everyone. Welcome to the eoeandroid community. Welcome to here! </String>
I want
Hello everyone, welcome to the eoeandroid community.
Welcome to here!
What should I do if two rows are output in the form? Add \ n, see the following:
 
<String name = "hello"> hello, everyone. Welcome to the eoeandroid community. \ Nwelcome to here! </String> 


Tips for adding spaces before and after string. xml in android
<String name = "space"> & #160; & #160; & #160; & #160; let me see spaces </string>
& #160; this represents a space
 

1. If the following error occurs, you must add the Escape Character (\) to the single quotation mark signature (\):
Description Resource Path Location Type error: Apostrophe not preceded by \ (in Search 'titles) strings. xml
You only need to change the single quotes (') in the defined string (\').
 

2. variable Text Format (% s) Prompt:
Multiple annotations found at this line:
-Error: Multiple substitutions specified in non-positional format; did you mean to add the formatted = "false"
Attribute?
-Error: Unexpected end tag string
This is because the new SDK (although not old) uses the new version of aapt (Android project compiler), this version of aapt compilation will be more rigorous than the old version, in the latest Android development documentation, the String section describes how to set symbols such as % s. You can click to view them.
The simple solution is to replace the format of variables such as % s with % 1 $ s. % 1 indicates the variable at the first position, and $ s indicates the string type.
For example:

<String name = "welcome_messages"> Your First Var is % 1 $ s! You Second Var is % 2 $ d. </string>

XML escape characters
The numbers and string escape characters of the XML flag are as follows:
"(& #34; or & quot ;)
'(& #39; or & apos ;)
& (& #38; or & amp ;)
Lt (<) (& #60; or & lt ;)
Gt (>) (& #62; or & gt ;)

Example:
For example, the following string is defined in string. xml,
<String name = "first"> hello, everyone. Welcome to the eoeandroid community. Welcome to here! </String>
I want
Hello everyone, welcome to the eoeandroid community.
Welcome to here!
What should I do if two rows are output in the form? Add \ n, see the following:
 
<String name = "hello"> hello, everyone. Welcome to the eoeandroid community. \ Nwelcome to here! </String> 


Tips for adding spaces before and after string. xml in android
<String name = "space"> & #160; & #160; & #160; & #160; let me see spaces </string>
& #160; this represents a space
 

1. If the following error occurs, you must add the Escape Character (\) to the single quotation mark signature (\):
Description Resource Path Location Type error: Apostrophe not preceded by \ (in Search 'titles) strings. xml
You only need to change the single quotes (') in the defined string (\').
 

2. variable Text Format (% s) Prompt:
Multiple annotations found at this line:
-Error: Multiple substitutions specified in non-positional format; did you mean to add the formatted = "false"
Attribute?
-Error: Unexpected end tag string
This is because the new SDK (although not old) uses the new version of aapt (Android project compiler), this version of aapt compilation will be more rigorous than the old version, in the latest Android development documentation, the String section describes how to set symbols such as % s. You can click to view them.
The simple solution is to replace the format of variables such as % s with % 1 $ s. % 1 indicates the variable at the first position, and $ s indicates the string type.
For example:

<String name = "welcome_messages"> Your First Var is % 1 $ s! You Second Var is % 2 $ d. </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.