Unicode转中文
function decodeUnicode() {
let input = area_input.value;
area_output.value = unescape(input.replace(/\\u/gi, '%u'));
}
Unicode编码
function encodeUnicode() {
let input = area_input.value;
let res = [];
for (let i = 0; i < input.length; i++) {
res[i] = ("00" + input.charCodeAt(i).toString(16)).slice(-4);
}
area_output.value = "\\u" + res.join("\\u");
}
ASCII转Unicode
function asciiToUnicode() {
let input = area_input.value;
let code = input.match(/&#(\d+);/g);
let result = '';
if (code === null) {
area_output.value = '';
return
}
for (let i = 0; i < code.length; i++) {
result += String.fromCharCode(code[i].replace(/[&#;]/g, ''));
}
area_output.value = result;
}
Unicode转ASCII
function unicodeToAscii() {
let input = area_input.value;
let result = '';
for (let i = 0; i < input.length; i++) {
result += '&#' + input.charCodeAt(i) + ';';
}
area_output.value = result;
}
效果