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 nextend functionfunction getnextchar(chrcode)'獲取下一個字符 if chrcode=57 then'數字和字母標ascii不連貫,需要特殊處理一下 getnextchar="a" else getnextchar=chr(chrcode+1) end ifend functionfunction 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) nextend functions=""initlen=6s=getnextno(s,initlen)msgbox s'000000s=getnextno(s,initlen)msgbox s'000001s="aaazzz"s=getnextno(s,initlen)msgbox s'aab000s="zzzzzz"s=getnextno(s,initlen)msgbox s'已經達到最大長度,無法繼續進位,需要修改長度</script>
新聞熱點
疑難解答