Javascript has built-in conversion functions: String.fromcharcodeat (), string.charcodeat () for converting between strings and encodings.
So what we're going to do with the string is actually very simple, we can get the Unicode encoding of the string directly using the String.charcodeat () function, where the number is decimal, and we number.tostring () the method, The 16-in-binary Unicode encoding of the string can be active.
By assembling, we can get a standard Unicode form of string, as described in the following ways:
The code is as follows |
Copy Code |
function Tounicode (str) { var temp, i = 0, R = ', len = str.length;
for (; i < Len; i++) { temp = Str.charcodeat (i). toString (16);
while (Temp.length < 4) temp = ' 0 ' + temp;
R + + ' \\u ' + temp; };
return R; } |
So how do we convert the Unicode code to Chinese?
The following methods are commonly used for converting such data to Chinese problems.
code is as follows |
copy code |
1. Eval resolution or New Function ("' + str + '") () str = eval ("" + str + ""); "I am Unicode Encoding" 2. unescape resolves str = unescape (str.replace (/\u/g, "%u"));//"I am Unicode Encoding" |