String.prototype.charCodeAt
String.fromCharCode ()
String.prototype.toUtfArray = function () {return This.split ("). Reduce (function (A, c) {var code = c.charcodeat (0); A.push (Code >> 8); A.push (code & 0X0FF); return A;}, []);}; String.fromutfarray = function (a) {//length even number of the previous 0if (a.length% 2 ===1) {a.unshift (0);} var wa = [], code = 0;for (var i = 0; i< a.length; i++) {if (i%2===0) {code = A[i] << 8;} else {code |= A[I];WA.P Ush (code);}} Return Wa.map (function (c) {return String.fromCharCode (c);}). Join (');};
Test
var S1 = "Hello a"; var a = S1.toutfarray (); [+, 0, 97]console.log, a.tostring ()], var s2 = String.fromutfarray (a); Console.log (S2); "Hello a"
* UTF-8 to grow longer
Character UTF-8 encoding byte 1 byte 2 byte 3
A 01000001
? 11000011 10010110
Medium 11100100 10111000 10101101
---------------------------------------------------------
Binary Hex Comments
0xxxxxxx 0x00.. 0x7F only byte of a 1-byte character encoding
10xxxxxx 0x80. 0xBF Continuation bytes (1-3 continuation bytes)
110xxxxx 0xC0. 0xDF first byte of a 2-byte character encoding
1110xxxx 0xE0. 0xEF first byte of a 3-byte character encoding
11110xxx 0xF0. 0xf7 first byte of a 4-byte character encoding
JavaScript wchar_t wide character converted to ASCII character code array