<script> /* **************************** * 半角<=>全角 * * [NB聯盟] * * Writer YuPing * **************************** *參數說明: * str:要轉換的字符串 * flag:標記,為0時半轉全,為非0時全轉半 * 返回值類型:字符串 **************************** */ function DBC2SBC(str,flag) { var i; var result=''; if (str.length<=0) {alert('字符串參數出錯');return false;} for(i=0;i<str.length;i++) { str1=str.charCodeAt(i); if(str1<125&&!flag) result+=String.fromCharCode(str.charCodeAt(i)+65248); else result+=String.fromCharCode(str.charCodeAt(i)-65248); } return result; } //示例: alert(DBC2SBC("AAabc",0)); document.write(DBC2SBC("abcdefg",0)) </script> <input type=text value="abcdefg" id=txt><input type=button value="變" onclick=txt.value=DBC2SBC(txt.value)>
<script language="vbscript"> '**************************** '* 半角<=>全角 * '* [NB聯盟] * '* Writer YuPing * '**************************** '*參數說明: '* str:要轉換的字符串 '* flag:標記,為0時半轉全,為非0時全轉半 '* 返回值類型:字符串 '**************************** function DBC2SBC(str,flag) dim i if len(str)<=0 then msgbox '字符串參數出錯' exit function end if for i=1 to len(str) str1=asc(mid(str,i,1)) if str1>0 and str1<=125 and not flag then dbc2sbc=dbc2sbc&chr(asc(mid(str,i,1))-23680) else dbc2sbc=dbc2sbc&chr(asc(mid(str,i,1))+23680) end if next end function '示例: alert(dbc2sbc("AB",1)) </script>
|