[資料]全形半形轉換[NB聯盟](ASP,JavaScript)代碼

來源:互聯網
上載者:User
/*
****************************
*     半形<=>全形    *
*           [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))'****************************
'*     半形<=>全形    *
'*           [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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.