使用vbscript生成36进制自动增长序号的实现代码
asp生成0~9,a~z的36进制字符串,运行下面示例需要使用IE核心的浏览器,其他非IE核心浏览器不支持vbscript。
实现代码:
<scriptlanguage="vbscript"> functiongetinitstring(l)'初始化指定长度的0字符串 l=l-1 fori=0tol getinitstring="0"&getinitstring next endfunction functiongetnextchar(chrcode)'获取下一个字符 ifchrcode=57then'数字和字母标ascii不连贯,需要特殊处理一下 getnextchar="a" else getnextchar=chr(chrcode+1) endif endfunction functiongetnextno(s,l)'获取下自增1的字符串 iftrim(s)=""then'初始化字符串 getnextno=getinitstring(l):exitfunction endif l=len(s)-1 dima():redima(l) fori=0tol'拆分成数组 a(i)=mid(s,i+1,1) next carry=false'进位标志 fori=lto0step-1'从最低位开始遍历 chrcode=asc(a(i)) ifcarrythen ifchrcode<>122then'不是z,自增后退出for循环,否则继续进位 a(i)=getnextchar(chrcode):exitfor'退出循环 elseifi=0then getnextno="已经达到最大长度,无法继续进位,需要修改长度":exitfunction endif endif ifa(i)="z"then carry=true:a(i)="0" else a(i)=getnextchar(chrcode):exitfor'退出循环 endif next fori=0tol'组合返回字符串 getnextno=getnextno&a(i) next endfunction s="" initlen=6 s=getnextno(s,initlen) msgboxs'000000 s=getnextno(s,initlen) msgboxs'000001 s="aaazzz" s=getnextno(s,initlen) msgboxs'aab000 s="zzzzzz" s=getnextno(s,initlen) msgboxs'已经达到最大长度,无法继续进位,需要修改长度 </script>