Vu *_*yen 5 javascript escaping
我有一个十六进制代码1f610,使格式字符串\u{1f610}与 in display. But how can I unescape it from the hex code?
I did
var code = '1f610';
unescape('%u' + code); //=> ?0
unescape('%u' + '{' + code + '}'); //=> %u{1f610}
Run Code Online (Sandbox Code Playgroud)
what should I do to unescape it to ?
这是一个星体集字符,在 JavaScript 字符串中需要两个字符。
改编自维基百科:
var code = '1f610';
var unicode = parseInt(code, 16);
var the20bits = unicode - 0x10000;
var highSurrogate = (the20bits >> 10) + 0xD800;
var lowSurrogate = (the20bits & 1023) + 0xDC00;
var character = String.fromCharCode(highSurrogate) + String.fromCharCode(lowSurrogate);
console.log(character);Run Code Online (Sandbox Code Playgroud)
<!-- results pane console output; see http://meta.stackexchange.com/a/242491 -->
<script src="http://gh-canon.github.io/stack-snippet-console/console.min.js"></script>Run Code Online (Sandbox Code Playgroud)
(另请注意,该unescape函数已被弃用。)
| 归档时间: |
|
| 查看次数: |
361 次 |
| 最近记录: |