preface

In daily development, you sometimes encounter the display of special characters, such as mathematical symbols, Roman characters, special units, and so on. Common characters can be typed directly, but powers, derivatives, integrals, chemical equations, and so on cannot be typed directly.

Currently, in addition to direct input, the STRING. XML can also be represented by ASCII characters. But ASCII characters are only a few hundred characters in common use, far from meeting the needs of special characters. After reviewing Android’s official description of strings, it turns out that Strings also support Unicode codes, so consider using Unicode codes to display special characters.

Unicode is with double byte 16 for number, programmable 65536 characters, basically contains all the language character in the world, it has become a common coding around the world, and expressed in hexadecimal to four a code, very intuitive Jane, accepted by most developers, especially after the hexadecimal code, It can solve the problem of garbled characters in the process of JS encoding and improve the speed of interpretation. We suggest using hexadecimal Unicode encoding in JS scripts.

application

Here are a few examples:

  1. power
XML string. < string name = "unit_ten_12_l formatted =" false "> x 10 \ u00B9 \ u00B2 / L < / string >Copy the code

This is x10 to the 12th over L. That’s 10 to the 12th per liter, as shown below

  1. Chemical equation

Carbon dioxide is generally expressed as CO2

This is expressed in the code as follows

string.xml
 <string name="co2" formatted="false">CO\u2082</string>
Copy the code

The preview is shown below

  1. Paragraph subheadings

To add layer to paragraphs, subheadings are added to separate them, either by cutting the diagram or using drawable

string.xml
<string name="title_01" formatted="false">\u2780</string>
Copy the code

The preview is shown below

  1. Roman numerals

Sometimes Roman numerals are used for paragraph headings, denoting 123 and appearing as ⅰ, ⅱ, ⅲ

string.xml
<string name="title_01" formatted="false">\u2160 \u2161 \u2162 \u2163</string>
Copy the code

The preview is shown below

conclusion

These are just a few examples to show that Unicode codes are over 60,000 characters long and can contain almost every common language and text in the world, and there are many more usage scenarios to be discovered.