幾個(gè)常用的asp自造函數(shù)
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
[p]getrepeattimes(thechar,thestring) 得到一個(gè)字符串在另一個(gè)字符串當(dāng)中出現(xiàn)幾次的函數(shù)(新)[br][br]如:[br]response.write getrepeattimes("w",aspxhome.com) [br]response.write getrepeattimes("ww","wwwww")[br]在網(wǎng)上看到過(guò)一個(gè)checkthechar(thechar,thestring)函數(shù),有個(gè)bug,在檢測(cè)wwwww中有幾個(gè)ww時(shí),會(huì)錯(cuò)誤的返回4個(gè)![br][br]cleft(string, length) 返回指定數(shù)目的從字符串的左邊算起的字符,區(qū)分單雙字節(jié)。[br][br]如:[br]dim mystring, leftstring [br]mystring = "文字測(cè)試vbscript" [br]leftstring = cleft(mystring, 10) [br]返回 "文字測(cè)試vb"。[br][br][br]myrandc(n) 生成隨機(jī)字符,n為字符的個(gè)數(shù)[br][br]如:[br]response.write myrandn(10)[br]輸出10個(gè)隨機(jī)字符[br][br][br]myrandn(n) 生成隨機(jī)數(shù)字,n為數(shù)字的個(gè)數(shù)[br][br]如:[br]response.write myrandn(10)[br]輸出10個(gè)隨機(jī)數(shù)字[br][br][br]formatquerystr(str) 格式化sql中的like字符串.[br]如:[br]q = request("q") [br]q = formatquerystr(q) [br]sql = "select * from [table] where aa like ’%"& q &"%’"[br]getrnd(min,max) 返回min - max之間的一個(gè)隨機(jī)數(shù)[br][br]如:[br]response.write getrnd(100,200)[br]輸出大于100到200之間的一個(gè)隨機(jī)數(shù)[br][br]regreplace(str,regexstr,repalcestr) 對(duì)str 進(jìn)行正則替換[br][br]如:[br]htmlstr = "123456" [br]htmlstr2 = regreplace(htmlstr,"<(.[^><]*)>","")[br]返回 htmlstr2 為123456[br][br]所有函數(shù)如下:[br]function cleft(str,n)[br]dim str1,str2,alln,islefted[br]str2 = ""[br]alln = 0[br]str1 = str[br]islefted = false[br]if isnull(str) then[br] cleft = ""[br] exit function[br]end if[br]for i = 1 to len(str1)[br] nowstr = mid(str1,i,1)[br] if asc(nowstr)<0 then[br] alln = alln + 2[br] else[br] alln = alln + 1[br] end if[br] if (alln<=n) then[br] str2 = str2 & nowstr[br] else[br] islefted = true[br] exit for[br] end if[br]next[br]if islefted then[br] str2 = str2 & ".."[br]end if[br]cleft = str2[br]end function[br][br][br]function myrandc(n) '生成隨機(jī)字符,n為字符的個(gè)數(shù)[br]dim thechr[br]thechr = ""[br]for i=1 to n[br] dim znum,znum2[br] randomize[br] znum = cint(25*rnd)[br] znum2 = cint(10*rnd)[br] if znum2 mod 2 = 0 then[br] znum = znum + 97[br] else[br] znum = znum + 65[br] end if[br] thechr = thechr & chr(znum)[br]next[br]myrandc = thechr[br]end function[br][br][br]function myrandn(n) '生成隨機(jī)數(shù)字,n為數(shù)字的個(gè)數(shù)[br]dim thechr[br]thechr = ""[br]for i=1 to n[br] dim znum,znum2[br] randomize[br] znum = cint(9*rnd)[br] znum = znum + 48[br] thechr = thechr & chr(znum)[br]next[br]myrandn = thechr[br]end function[br][br]function formatquerystr(str) '格式化sql中的like字符串[br]dim nstr[br]nstr = str[br]nstr = replace(nstr,chr(0),"")[br]nstr = replace(nstr,"'","''")[br]nstr = replace(nstr,"[","[[]")[br]nstr = replace(nstr,"%","[%]")[br]formatquerystr = nstr[br]end function[br][br]function getrnd(min,max)[br]randomize[br]getrnd = int((max - min + 1) * rnd + min)[br]end function[br][br]function getrepeattimes(thechar,thestring)[br]getrepeattimes = (len(thestring)-len(replace(thestring,thechar,"")))/len(thechar)[br]end function[br][br]function regreplace(str,patternstr,repstr)[br]dim newstr,regex[br]newstr = str[br]if isnull(newstr) then[br] regreplace = ""[br] exit function[br]end if[br]set regex = new regexp[br]regex.ignorecase = true[br]regex.global = true[br]regex.pattern=patternstr[br]newstr = regex.replace(newstr,repstr)[br]regreplace = newstr[br]end function [br][/p]
該文章在 2010/7/23 0:15:32 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |