Function
cleft (string,length) returns the specified number of characters from the left side of the string, distinguishing between single and double bytes.
Such as:
Dimmystring,leftstring
mystring= "text Test VBScript"
Leftstring=cleft (mystring,10)
Return to "Text Test vb".
MYRANDC (n) generates random characters, n is the number of characters
Such as:
RESPONSE.WRITEMYRANDN (10)
Output 10 random characters
myrandn (n) generates random numbers, n is the number of numbers
Such as:
RESPONSE.WRITEMYRANDN (10)
Output 10 random digits
formatquerystr (str) formats the like string in SQL.
Such as:
Q=request ("q")
Q=FORMATQUERYSTR (q)
sql= "Select*from[table]whereaalike '%" &q& "%"
getrnd (Min,max) returns a random number between Min-max
Such as:
Response.writegetrnd (100,200)
Output is a random number greater than 100 to 200
Function code:
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) ' generates random characters, n is the number of characters
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) ' generates a random number, n is the number of numbers
Dimthechr
Thechr= ""
Fori=1ton
Dimznum,znum2
Randomize
Znum=cint (9*RND)
znum=znum+48
THECHR=THECHR&CHR (Znum)
Next
Myrandn=thechr
Endfunction
FUNCTIONFORMATQUERYSTR (str) ' format a like string in SQL
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