zoukankan      html  css  js  c++  java
  • 字符串提取替换后再替换回去 和 函数将数字转换中文数字

    function WriteAct(){
     var actlist=document.all.ActHTML.value
     var ActListOut=document.all.ActHTML_out;
     var num=new Array();
     var actlistText=""
     var actlistValue=new Array();
     var re=/.*第(\d+)条.*/ig
     var actNum=actlist.match(re)
     for(var i=0;i<actNum.length;i++){  
      actlistValue[i]=actNum[i].substring(actNum[i].indexOf("第")+1)
      actlistValue[i]=chnumstr(actlistValue[i].substring(0,actlistValue[i].indexOf("条")))
      actlistText+=actNum[i].replace(/第\d+条/ig,"第"+actlistValue[i]+"条"); 
     }
     ActListOut.innerHTML=actlistText;

    }


    function ChineseNum(num){//将阿拉伯数字翻译成中文的大写数字
     if(!/^\d*(\.\d*)?$/.test(num)){alert("Numberiswrong!");return false;}
     var AA=new Array("零","一","二","三","四","五","六","七","八","九");
     var BB= new Array("","十","百","千","万","亿","点","");
     var a=(""+num).replace(/(^0*)/g,"").split("."),k=0,re="";
     for(var i=a[0].length-1;i>=0;i--){  //author:meizz
      switch(k)
      {
       case 0:re=BB[7]+re;break;
       case 4:if(!newRegExp("0{4}\d{"+(a[0].length-i-1)+"}$").test(a[0]))
       re=BB[4]+re;break;
       case 8:re=BB[5]+re;BB[7]=BB[5];k=0;break;
      }
      if(k%4==2&&a[0].charAt(i)=="0"&&a[0].charAt(i+2)!="0")re=AA[0]+re;
      if(a[0].charAt(i)!=0)re=AA[a[0].charAt(i)]+BB[k%4]+re;k++;
     }
     if(a.length>1){//加上小数部分(如果有小数部分)
      re+=BB[6];
      for(vari=0;i<a[1].length;i++)re+=AA[a[1].charAt(i)];
     }
    }

    <script language="vbscript">
    function chnumstr(num)
     strlen=len(num)
     for i=1 to strlen
      select case mid(num,i,1)
       case 1:chnum="一":case 2:chnum="二":case 3:chnum="三":case 4:chnum="四":case 5:chnum="五"
       case 6:chnum="六":case 7:chnum="七":case 8:chnum="八":case 9:chnum="九":case 0:chnum="零"
      end select
      chnumstr=chnumstr&chnum
      if i=strlen-1 and mid(num,i,1)<>0 then chnumstr=chnumstr&"十"
      if i=strlen-2 and mid(num,i,1)<>0 then chnumstr=chnumstr&"百"
      if i=strlen-3 and mid(num,i,1)<>0 then chnumstr=chnumstr&"千"
      if i=strlen-4 and mid(num,i,1)<>0 then chnumstr=chnumstr&"万"
      if i=strlen-5 and mid(num,i,1)<>0 then chnumstr=chnumstr&"十"
      if i=strlen-6 and mid(num,i,1)<>0 then chnumstr=chnumstr&"百"
      if i=strlen-7 and mid(num,i,1)<>0 then chnumstr=chnumstr&"千"
      if i=strlen-8 and mid(num,i,1)<>0 then chnumstr=chnumstr&"万"
     next
    end function
    </script>

  • 相关阅读:
    netty集成springboot
    NIO-BufferAPI
    python专题知识追寻者对OS的理解
    python专题文件操作
    我终于学会了使用python操作postgresql
    跟着知识追寻者学BeautifulSoup,你学不会打不还口,骂不还手
    那些不懂hystrix的秘密
    如何成为一名Web前端开发人员?
    css剪裁GIF背景图片动画特效
    css 变量教程
  • 原文地址:https://www.cnblogs.com/zengwei/p/803069.html
Copyright © 2011-2022 走看看