zoukankan      html  css  js  c++  java
  • HTML常用编码转换

    var encoding = (function () {
       function ToASCII(str) {
           return this.ToNormal(str).replace(/[^\u0000-\u00FF]/g, function () { return escape(arguments[0]).replace(/(?:%u)([0-9a-f]{4})/gi, "\$1;") });
       }
       function ToUnicode(str) {
           return this.ToNormal(str).replace(/[^\u0000-\u00FF]/g, function () { return escape(arguments[0]).replace(/(?:%u)([0-9a-f]{4})/gi, "\\u$1") });
       }
       function ToNormal(str) {
           return str.replace(/(?:)([0-9a-f]{4});|(?:\\u)([0-9a-f]{4})/gi, function () { return unescape("%u" + (arguments[1] || arguments[2])); });
       }
       function ToCss(str) {
           return this.ToNormal(str).replace(/[^\u0000-\u00FF]/g, function () { return escape(arguments[0]).replace(/(?:%u)([0-9a-f]{4})/gi, "\\$1") });
       }
       return {
           ToASCII: ToASCII,
           ToUnicode: ToUnicode,
           ToNormal: ToNormal,
           ToCss: ToCss
       };
    })();
    console.log(encoding.ToASCII("宋体"));
    console.log(encoding.ToUnicode("宋体"));
    console.log(encoding.ToNormal("宋\\u4F53"));
    console.log(encoding.ToUnicode("宋体"));
    console.log(encoding.ToCss('Arial , Helvetica ,"宋体", sans-serif'));
    转载自:http://www.w3cplus.com/code/473.html
  • 相关阅读:
    codefoces 1405 D Tree Tag
    洛谷P3413 萌数
    数位DP模板
    leetcode 统计所有可行路径
    Josephus Transform 加速置换
    牛客IOI周赛18-提高组 排列
    Find a way HDU
    Oil Deposits HDU
    Fire! UVA
    Pots POJ
  • 原文地址:https://www.cnblogs.com/lyweb/p/unicode.html
Copyright © 2011-2022 走看看