String.fromCharCode(parseInt("0x" + RegExp.$1))

解决方案 »

  1.   

    另外...
    这种字符串其实可以这样获取...
    alert(eval('"' + s + '"'))
      

  2.   

    String.fromCharCode(parseInt("0x" + RegExp.$1)) 要放到哪里?var re = new RegExp("\\\\x(\\d\\d)", "ig");
    var s = "\\x41\\x42";
    alert(s.replace(re, String.fromCharCode(parseInt("0x" + RegExp.$1))));
    弹出的窗口显示的是"BB"。怎么回事?
      

  3.   

    现在只能这样了!var re = new RegExp("\\\\x(\\d\\d)", "ig");
    var s = "\\x41\\x42";
    var t = s, arr;
    while ((arr = re.exec(s)) != null) {
        t = t.replace(arr[0], String.fromCharCode(parseInt('0x' + arr[1])));
    }
    alert(t);