请问小程序中&#开头的字符编码如何解析成字符
有些文字从后台获取过来是类似 中国 的,在小程序中如何解析成字符
有些文字从后台获取过来是类似 中国 的,在小程序中如何解析成字符
var hahaha = '中 哈哈哈哈哈😄哈哈😄'; var text = hahaha.replace(/&#.{5,6};/g,function(res){ res = res.substring(2, res.length-1); if (res.indexOf('x') == 0) { res = res.substring(1); return String.fromCodePoint(parseInt(res, 16)); } return String.fromCodePoint(parseInt(res, 10)); }); |
unicode吧。我不是很熟。。如果你确定后台给你的这个是个String类型,我只知道很傻的方式
let a = “中国 ”
let b = unescape(escape(a).replace(/%26%23x/ig,‘%u’).replace(/%3B/g,‘’))
console.log(b) 或者 String(b) 或者不需要额外处理了