zoukankan      html  css  js  c++  java
  • JavaScript 实现字符与unicode编码的相互转换

    这种转换主要用来加密js代码.
    这两个函数参考了[脚本之家] (http://www.jb51.net/html/200707/23/10560.htm ) 的代码, 但是他的函数是错的, 我不知道为什么那个作者要那样写, 所以我改写了一下 .

    function unicode2Chr(str)
    {
     if (str!='')
     {
      var fret, tempStr;
      fret = '';
      for (var i = 1; i <= str.length/4; i ++)
      {
       tempStr = str.slice(4*i-4, 4*i);
       fret = fret.concat('%u').concat(tempStr);
      }
      fret = unescape(fret);
      return(fret);
     }
     else
      return('');
    }


    function chr2Unicode(str)
    {
     if (str!='')
     {
      var fret, tempStr;
      fret = '';
      for (var i = 1; i <= str.length; i ++)
      {
       tempStr = str.charCodeAt(i - 1).toString(16);
       if (tempStr.length < 4)
        while(tempStr.length <4)
             tempStr = '0'.concat(tempStr);
       tempStr = tempStr.slice(0, 4);
       fret = fret.concat(tempStr);
      }
      return(fret.toUpperCase());
     }
     else
      return(''); 
    }

  • 相关阅读:
    hdu2084 DP
    hdu 2080 夹角有多大(弧度制)
    hdu2078复习时间
    hdu2077
    hdu 2051
    hdu 2050
    hdu 5514Frogs
    ARM指令
    ARM寄存器
    树莓派ARM汇编
  • 原文地址:https://www.cnblogs.com/Moosdau/p/908921.html
Copyright © 2011-2022 走看看