日期:2011-10-09  浏览次数:21086 次

cLeft(string,length) 返回指定数目的从字符串的左边算起的字符,区分单双字节。

如:
DimMyString,LeftString
MyString="文字测试VBSCript"
LeftString=cLeft(MyString,10)
返回"文字测试VB"。


MyRandc(n) 生成随机字符,n为字符的个数

如:
response.writeMyRandn(10)
输出10个随机字符


MyRandn(n) 生成随机数字,n为数字的个数

如:
response.writeMyRandn(10)
输出10个随机数字


formatQueryStr(str) 格式化sql中的like字符串.
如:
q=Request("q")
q=formatQueryStr(q)
sql="select*from[table]whereaalike'%"&q&"%'"

GetRnd(min,max) 返回min-max之间的一个随机数

如:
response.writeGetRnd(100,200)
输出大于100到200之间的一个随机数

函数代码:

functioncLeft(str,n)
 dimstr1,str2,alln,Islefted
 str2=""
 alln=0
 str1=str
 Islefted=false
 ifisnull(str)then
  cleft=""
  exitfunction
 endif
 fori=1tolen(str1)
  nowstr=mid(str1,i,1)
  ifasc(nowstr)<0then
   alln=alln+2
  else
   alln=alln+1
  endif
  if(alln<=n)then
   str2=str2&nowstr
  else
   Islefted=true
   exitfor
  endif
 next
 ifIsleftedthen
  str2=str2&".."
 endif
 cleft=str2
endfunction


functionMyRandc(n) '生成随机字符,n为字符的个数
 dimthechr
 thechr=""
 fori=1ton
  dimzNum,zNum2
  Randomize
  zNum=cint(25*Rnd)
  zNum2=cint(10*Rnd)
  ifzNum2mod2=0then
   zNum=zNum+97
  else
   zNum=zNum+65
  endif
  thechr=thechr&chr(zNum)
 next
 MyRandc=thechr
endfunction


functionMyRandn(n) '生成随机数字,n为数字的个数
 dimthechr
 thechr=""
 fori=1ton
  dimzNum,zNum2
  Randomize
  zNum=cint(9*Rnd)
  zNum=zNum+48
  thechr=thechr&chr(zNum)
 next
 MyRandn=thechr
endfunction

functionformatQueryStr(str) '格式化sql中的like字符串
 dimnstr
 nstr=str
 nstr=replace(nstr,chr(0),"")
 nstr=replace(nstr,"'","''")
 nstr=replace(nstr,"[","[[]")
 nstr=replace(nstr,"%","[%]")
 formatQueryStr=nstr
endfunction

functionGetRnd(min,max)
 Randomize
 GetRnd=Int((max-min+1)*Rnd+min)
endfunction