這篇文章主要介紹了使用vbscript生成36進制自動增長序號的實現代碼,本文代碼也可以在ASP中使用,需要的朋友可以參考下
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 s'000000
- s=getnextno(s,initlen)
- msgbox s'000001
- s="aaazzz"
- s=getnextno(s,initlen)
- msgbox s'aab000
- s="zzzzzz"
- s=getnextno(s,initlen)
- msgbox s'已經達到最大長度,無法繼續進位,需要修改長度
- </script>
新聞熱點
疑難解答