Unicode转中文,Unicode编码转换,ASCII转Unicode,Unicode转ASCII

DEMO https://oktools.net/unicode

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;
      
    }

效果

Unicode转中文,Unicode编码转换,ASCII转Unicode,Unicode转ASCII

上一篇:【访问控制】STS接口调用提示权限报错排查思路


下一篇:JavaScript 和asp.net配合编码字符串