当前位置: 代码迷 >> HTML/CSS >> word存的html中的unicode汉语转码为标准中文
  详细解决方案

word存的html中的unicode汉语转码为标准中文

热度:178   发布时间:2013-08-04 18:26:16.0
word存的html中的unicode中文转码为标准中文
 var fs = require("fs");
  
  
   fs.readFile("page.htm",function(err,data){
      var str = data.toString();
      var matchs = str.match(/&#[0-9]{5};/gm);
      for(var i = 0 ; i < matchs.length ; i++){
          var ma = matchs[i];
          var a = ma.replace("&#","").replace(";","");
          a = parseInt(a).toString(16);
          console.log(unescape('%u'+a));
          str = str.replace(ma,unescape("%u"+a));
      }
      fs.writeFile("out.htm",str,function(){
          console.log("写入成功");
     })
     console.log(matchs.length,matchs[0]);
 })

?

  相关解决方案