php的这样写:
$value = preg_replace('/\xa3([\xa1-\xfe])/e', 'chr(ord(\1)-0x80)', $value); js的有没有人告诉一下

解决方案 »

  1.   

    function SBC(text) {
        return text && text.replace(/[\x20-\x7e]/g, function($0) {
            return $0 == " " ? "\u3000" : String.fromCharCode($0.charCodeAt(0) + 0xfee0);
        });
    }function CBS(text) {
        return text && text.replace(/[\u3000\uff01-\uff5f]/g, function($0) {
            return $0 == "\u3000" ? " " : String.fromCharCode($0.charCodeAt(0) - 0xfee0);
        });
    }alert(SBC("zswang 2010"));
    alert(CBS("zswang 2010"));
      

  2.   


    不太完美吧!正则的全角范围应该是[\u3000\uff01-\uffE6]  
    http://unicodelookup.com/#fullwidth/1