全角半角文字列はJavaScriptを相互に回転します.

883 ワード


半角を全角に変換
 
function SBC(text) {
    return text.replace(/[\x20-\x7e]/g, function($0) {
        return $0 == " " ? "\u3000" : String.fromCharCode($0.charCodeAt(0) + 0xfee0);
    });
}
 
 
function n2c(n) {
    var s= n.toString().split(''), 
    r='';
    for (var i=0, length= s.length; i< length; i++) {
        r+='0123456789'.split('')[s[i]];
    }
    return r;
}
 
 
全角を半角に変換
function dbc2sbc(s){
     return s.replace(/[\uff01-\uff5e]/g,
            function(a){
                  return String.fromCharCode(a.charCodeAt(0)-5248);
            }
      ).replace(/\u3000/g," ");
}