asp/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 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>

 

加支付宝好友偷能量挖...


原创文章,转载请注明出处:asp/vbscript 36进制自动增长序号

评论(0)Web开发网
阅读(141)喜欢(1)Asp/VBScript