2016-01-19 19 views
5

1f610 kodlu bir kodum var, bu nedenle biçim dizesi göstergede görüntülenir. Ancak, onaltılık koddan nasıl ayırabilirim?javascript unescape onaltılık hizada

Ben

var code = '1f610'; 

unescape('%u' + code); //=> ὡ0 

unescape('%u' + '{' + code + '}'); //=> %u{1f610} 

Ben bunu okunabilir hale getirmek için ne yapmalıyız yaptı?

+0

Google, bu cevap beni çekti: http://stackoverflow.com/questions/4209104/decoding-hex-string-in-javascript – dovidweisz

+0

Denedim ama işe yaramadı, teşekkürler @wapsee :) –

cevap

2

Bu, bir JavaScript dizesinde iki karakter gerektiren bir astral set karakteridir.

Wikipedia uyarlanmıştır:

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);
<!-- 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>
(Ayrıca unescape işlevi deprecatd unutmayın.)