getrepeattimes(thechar,thestring) 得到一個字符串在另一個字符串當中出現(xiàn)幾次的函數(新)
如:
response.write getrepeattimes("w",aspxhome.com)
response.write getrepeattimes("ww","wwwww")
在網上看到過一個checkthechar(thechar,thestring)函數,有個bug,在檢測wwwww中有幾個ww時,會錯誤的返回4個!
cleft(string, length) 返回指定數目的從字符串的左邊算起的字符,區(qū)分單雙字節(jié)。
如:
dim mystring, leftstring
mystring = "文字測試vbscript"
leftstring = cleft(mystring, 10)
返回 "文字測試vb"。
myrandc(n) 生成隨機字符,n為字符的個數
如:
response.write myrandn(10)
輸出10個隨機字符
myrandn(n) 生成隨機數字,n為數字的個數
如:
response.write myrandn(10)
輸出10個隨機數字
formatquerystr(str) 格式化sql中的like字符串.
如:
q = request("q")
q = formatquerystr(q)
sql = "select * from [table] where aa like ’%"& q &"%’"
getrnd(min,max) 返回min - max之間的一個隨機數
如:
response.write getrnd(100,200)
輸出大于100到200之間的一個隨機數
regreplace(str,regexstr,repalcestr) 對str 進行正則替換
如:
htmlstr = "123456"
htmlstr2 = regreplace(htmlstr,"<(.[^><]*)>","")
返回 htmlstr2 為123456
所有函數如下:
function cleft(str,n)
dim str1,str2,alln,islefted
str2 = ""
alln = 0
str1 = str
islefted = false
if isnull(str) then
cleft = ""
exit function
end if
for i = 1 to len(str1)
nowstr = mid(str1,i,1)
if asc(nowstr)<0 then
alln = alln + 2
else
alln = alln + 1
end if
if (alln<=n) then
str2 = str2 & nowstr
else
islefted = true
exit for
end if
next
if islefted then
str2 = str2 & ".."
end if
cleft = str2
end function
function myrandc(n) '生成隨機字符,n為字符的個數
dim thechr
thechr = ""
for i=1 to n
dim znum,znum2
randomize
znum = cint(25*rnd)
znum2 = cint(10*rnd)
if znum2 mod 2 = 0 then
znum = znum + 97
else
znum = znum + 65
end if
thechr = thechr & chr(znum)
next
myrandc = thechr
end function
function myrandn(n) '生成隨機數字,n為數字的個數
dim thechr
thechr = ""
for i=1 to n
dim znum,znum2
randomize
znum = cint(9*rnd)
znum = znum + 48
thechr = thechr & chr(znum)
next
myrandn = thechr
end function
function formatquerystr(str) '格式化sql中的like字符串
dim nstr
nstr = str
nstr = replace(nstr,chr(0),"")
nstr = replace(nstr,"'","''")
nstr = replace(nstr,"[","[[]")
nstr = replace(nstr,"%","[%]")
formatquerystr = nstr
end function
function getrnd(min,max)
randomize
getrnd = int((max - min + 1) * rnd + min)
end function
function getrepeattimes(thechar,thestring)
getrepeattimes = (len(thestring)-len(replace(thestring,thechar,"")))/len(thechar)
end function
function regreplace(str,patternstr,repstr)
dim newstr,regex
newstr = str
if isnull(newstr) then
regreplace = ""
exit function
end if
set regex = new regexp
regex.ignorecase = true
regex.global = true
regex.pattern=patternstr
newstr = regex.replace(newstr,repstr)
regreplace = newstr
end function
該文章在 2010/7/23 0:15:32 編輯過