JavaScript word representable Unicode, by the way: GitHub's Oh no page is very bright

Source: Internet
Author: User

Encounter a lost character to do, because the characters are usually not out of the common most of the time even the name can not shout out, so want to ask Baidu Google is not very likely. If it is small white users will definitely go to the Input method floppy disk open switch to another keyboard one to find. Even if there is Sogou input method such a powerful collection of special character sets, but also to find AH.

That day on GitHub on the time of the careless error page (you still dispel the idea of repetition, it is difficult), a bullish chic, I go, sigh with question mark of the fit, I go what is this symbol?

What also table said maybe later in their own design to use, so copy down.

Later a think ah wrong ah, I can not play out, I want to use the time must be copied. This is not very safe. If you know his Unicode code, then you can use it in Html,javascript.

So now you need a function that can convert a character to a Unicode code.

The JavaScript built-in function has a string.fromcharcode () that turns Unicode into characters.

There's also a string.charcodeat () that representable Unicode to a character.

But note that this string.charcodeat () directly turns out the number is 10 binary, cannot in code like this normal use "\uxxxx".

So you need to call ToString (16), and note that you specify a base of 16.

The following auxiliary functions are then obtained:

function convert2unicode (char) {  returnchar. charCodeAt (0). ToString (+);}

Convert2unicode ("?") "\u203d"

So it can be used in JS: alert ("\u203d");

Advanced

Further, it can be thought that in addition to converting a character to a Unicode representation, a string can be converted with a slight modification.

function Tounicode (thestring) {  var unicodestring = ';    for (var i = 0; i < thestring.length; i++) {    var theunicode = Thestring.charcodeat (i). ToS Tring (+). toUpperCase ();      while (Theunicode.length < 4) {      = ' 0 ' + theunicode;    }     = ' \\u ' + theunicode;     + = Theunicode  ;  } return unicodestring;}

The

JavaScript word representable Unicode, by the way: GitHub's Oh no page is very bright

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.