使用vbscript生成36进制自动增长序号的实现代码 |
asp生成0'9,a'z的36进制字符串,运行下面示例需要使用IE核心的浏览器,其他非IE核心浏览器不支持vbscript 。 实现代码: <script language="vbscript"> function getinitstring(l)初始化指定长度的0字符串 l=l-1 for i=0 to l getinitstring="0"&getinitstring next end function function getnextchar(chrcode)获取下一个字符 if chrcode=57 then数字和字母标ascii不连贯,需要特殊处理一下 getnextchar="a" else getnextchar=chr(chrcode+1) end if end function function getnextno(s,l)获取下自增1的字符串 if trim(s)="" then初始化字符串 getnextno=getinitstring(l):exit function end if l=len(s)-1 dim a():redim a(l) for i=0 to l拆分成数组 a(i)=mid(s,i+1,1) next carry=false进位标志 for i=l to 0 step -1从最低位开始遍历 chrcode=asc(a(i)) if carry then if chrcode<>122 then不是z,自增后退出for循环,否则继续进位 a(i)=getnextchar(chrcode):exit for退出循环 elseif i=0 then getnextno="已经达到最大长度,无法继续进位,需要修改长度":exit function end if end if if a(i)="z" then carry=true:a(i)="0" else a(i)=getnextchar(chrcode):exit for退出循环 end if next for i=0 to l组合返回字符串 getnextno=getnextno&a(i) next end function s="" initlen=6 s=getnextno(s,initlen) msgbox s000000 s=getnextno(s,initlen) msgbox s000001 s="aaazzz" s=getnextno(s,initlen) msgbox saab000 s="zzzzzz" s=getnextno(s,initlen) msgbox s已经达到最大长度,无法继续进位,需要修改长度 </script> |