再發(fā)幾個(gè)ASP不錯(cuò)的函數(shù)
更新時(shí)間:2007年08月18日 22:37:46 作者:
********************
'函數(shù)作用:根據(jù)條件真假返回選定值中的某個(gè)
'參數(shù):blnCondition:條件變量,varResultTrue:條件為真時(shí)返回值,varResultFalse:條件為假時(shí)返回值
Function IIF(blnCondition, varResultTrue,varResultFalse)
If CBool(blnCondition) Then
IIF = varResultTrue
Else
IIF = varResultFalse
End If
End Function
'********************
'函數(shù)作用:判斷某個(gè)字符串元素是否在給定枚舉中
'參數(shù):sEle:待判斷的字符串,sArray:指定枚舉
'舉例:根據(jù)擴(kuò)展名判斷是否圖片文件:InArray(strFileExt,"jpg,gif,bmp,png")
Function InArray(sEle,sArray)
Dim aArray
Dim i
aArray = Split(sArray,",")
For i = 0 To UBound(aArray)
If Trim(sEle) = Trim(aArray(i)) Then
InArray = True
Exit Function
End If
Next
InArray = False
End Function
'********************
'函數(shù)作用:判斷某個(gè)字符串是否符合正則表達(dá)式
'參數(shù):strString:字符串,strPattern:正則表達(dá)式
Function doReTest(strString, strPattern)
Dim oRE
Set oRE = New RegExp
oRE.Pattern = strPattern
oRE.IgnoreCase = True
doReTest = oRE.Test(strString)
Set oRE = Nothing
End Function
'********************
'函數(shù)作用:正則提取
'參數(shù):string:字符串,patrn:正則表達(dá)式
'返回:逗號(hào)分割的結(jié)果數(shù)組集成
Function doReExec(strng,patrn)
Dim regEx, Match, Matches,RetStr ' 創(chuàng)建變量。
Set regEx = New RegExp ' 創(chuàng)建正則表達(dá)式。
regEx.Pattern = patrn ' 設(shè)置模式。
regEx.IgnoreCase = True ' 設(shè)置為不區(qū)分大小寫。
regEx.Global = True ' 設(shè)置全局適用。
Set Matches = regEx.Execute(strng) ' 執(zhí)行搜索。
For Each Match in Matches ' 對(duì) Matches 集合進(jìn)行迭代。
RetStr = RetStr & Match.Value & "," & vbCRLF
Next
doReExec = RetStr
End Function
復(fù)制代碼 '********************
'函數(shù)作用:顯示分頁(yè)鏈接
'參數(shù):lngCurPage:當(dāng)前頁(yè)是第幾頁(yè),lngPageCount:一共幾頁(yè),strSueryString:分頁(yè)鏈接需要附加的QueryString變量
Sub showPageNav(lngCurPage,lngPageCount,ByVal strQueryString)
Response.Write "當(dāng)前第" & lngCurPage & "頁(yè),共:" & lngPageCount & "頁(yè)"
Dim i,j,k
If lngCurPage = 1 Then '如果是第一頁(yè)
'如果lngPageCount小于10,則導(dǎo)航頁(yè)最多到lngPageCount頁(yè)
If lngPageCount < 10 Then
j = lngPageCount
Else
j = 10
End If
For i = 2 To j
Response.Write("<a href=""?" & strQueryString & "&p=" & i & """>" & i & "</a> ")
Next
ElseIf lngCurPage = lngPageCount Then '如果是最后一頁(yè)
'如果lngPageCount小于10,則導(dǎo)航起始從1開始
If lngPageCount < 10 Then
j = 1
Else
j = lngPageCount - 10
End If
For i = j To lngPageCount - 1
Response.Write("<a href=""?" & strQueryString & "&p=" & i & """>" & i & "</a> ")
Next
Response.Write(lPageCount)
Else '如果是中間的頁(yè)
If lngCurPage <= 5 Then
j = 1
Else
j = lngCurPage - 5
End If
If lngPageCount <= lngCurPage + 5 Then
k = lngPageCount
Else
k = lngCurPage + 5
End If
Response.Write("<a href=""?" & strQueryString & "&p=" & 1 & """>" & "<<" & "</a> ")
For i = j To lngCurPage - 1
Response.Write("<a href=""?" & strQueryString & "&p=" & i & """>" & i & "</a> ")
Next
Response.Write(lngCurPage & " ")
For i = lngCurPage + 1 To k
Response.Write("<a href=""?" & strQueryString & "&p=" & i & """>" & i & "</a> ")
Next
Response.Write(" <a href=""?" & strQueryString & "&p=" & lPageCount & """>" & ">>" & "</a>")
End If
End Sub
'********************
'函數(shù)作用:當(dāng)前頁(yè)請(qǐng)求方式是否為POST
'說明:用于在同一頁(yè)面處理顯示和數(shù)據(jù)操作,當(dāng)PostBack()為真時(shí)說明提交表單至當(dāng)前頁(yè),應(yīng)進(jìn)行數(shù)據(jù)后臺(tái)操作
Function PostBack()
If UCase(Trim(Request.ServerVariables("REQUEST_METHOD"))) = "POST" Then
PostBack = True
Else
PostBack = False
End If
End Function
'********************
'函數(shù)作用:返回執(zhí)行長(zhǎng)度的隨機(jī)字符串
'參數(shù):Length:長(zhǎng)度
Function GenRadomString(Length)
dim i, tempS, v
dim c(39)
tempS = ""
c(1) = "a": c(2) = "b": c(3) = "c": c(4) = "d": c(5) = "e": c(6) = "f": c(7) = "g"
c(8) = "h": c(9) = "i": c(10) = "j": c(11) = "k": c(12) = "l": c(13) = "m": c(14) = "n"
c(15) = "o": c(16) = "p": c(17) = "q": c(18) = "r": c(19) = "s": c(20) = "t": c(21) = "u"
c(22) = "v": c(23) = "w": c(24) = "x": c(25) = "y": c(26) = "z": c(27) = "1": c(28) = "2"
c(29) = "3": c(30) = "4": c(31) = "5": c(32) = "6": c(33) = "7": c(34) = "8": c(35) = "9"
If isNumeric(Length) = False Then
Response.Write "A numeric datatype was not submitted to this function."
Exit Function
End If
For i = 1 to Length
Randomize
v = Int((35 * Rnd) + 1)
tempS = tempS & c(v)
Next
GenRadomString = tempS
End Function
'函數(shù)作用:根據(jù)條件真假返回選定值中的某個(gè)
'參數(shù):blnCondition:條件變量,varResultTrue:條件為真時(shí)返回值,varResultFalse:條件為假時(shí)返回值
Function IIF(blnCondition, varResultTrue,varResultFalse)
If CBool(blnCondition) Then
IIF = varResultTrue
Else
IIF = varResultFalse
End If
End Function
'********************
'函數(shù)作用:判斷某個(gè)字符串元素是否在給定枚舉中
'參數(shù):sEle:待判斷的字符串,sArray:指定枚舉
'舉例:根據(jù)擴(kuò)展名判斷是否圖片文件:InArray(strFileExt,"jpg,gif,bmp,png")
Function InArray(sEle,sArray)
Dim aArray
Dim i
aArray = Split(sArray,",")
For i = 0 To UBound(aArray)
If Trim(sEle) = Trim(aArray(i)) Then
InArray = True
Exit Function
End If
Next
InArray = False
End Function
'********************
'函數(shù)作用:判斷某個(gè)字符串是否符合正則表達(dá)式
'參數(shù):strString:字符串,strPattern:正則表達(dá)式
Function doReTest(strString, strPattern)
Dim oRE
Set oRE = New RegExp
oRE.Pattern = strPattern
oRE.IgnoreCase = True
doReTest = oRE.Test(strString)
Set oRE = Nothing
End Function
'********************
'函數(shù)作用:正則提取
'參數(shù):string:字符串,patrn:正則表達(dá)式
'返回:逗號(hào)分割的結(jié)果數(shù)組集成
Function doReExec(strng,patrn)
Dim regEx, Match, Matches,RetStr ' 創(chuàng)建變量。
Set regEx = New RegExp ' 創(chuàng)建正則表達(dá)式。
regEx.Pattern = patrn ' 設(shè)置模式。
regEx.IgnoreCase = True ' 設(shè)置為不區(qū)分大小寫。
regEx.Global = True ' 設(shè)置全局適用。
Set Matches = regEx.Execute(strng) ' 執(zhí)行搜索。
For Each Match in Matches ' 對(duì) Matches 集合進(jìn)行迭代。
RetStr = RetStr & Match.Value & "," & vbCRLF
Next
doReExec = RetStr
End Function
復(fù)制代碼 '********************
'函數(shù)作用:顯示分頁(yè)鏈接
'參數(shù):lngCurPage:當(dāng)前頁(yè)是第幾頁(yè),lngPageCount:一共幾頁(yè),strSueryString:分頁(yè)鏈接需要附加的QueryString變量
Sub showPageNav(lngCurPage,lngPageCount,ByVal strQueryString)
Response.Write "當(dāng)前第" & lngCurPage & "頁(yè),共:" & lngPageCount & "頁(yè)"
Dim i,j,k
If lngCurPage = 1 Then '如果是第一頁(yè)
'如果lngPageCount小于10,則導(dǎo)航頁(yè)最多到lngPageCount頁(yè)
If lngPageCount < 10 Then
j = lngPageCount
Else
j = 10
End If
For i = 2 To j
Response.Write("<a href=""?" & strQueryString & "&p=" & i & """>" & i & "</a> ")
Next
ElseIf lngCurPage = lngPageCount Then '如果是最后一頁(yè)
'如果lngPageCount小于10,則導(dǎo)航起始從1開始
If lngPageCount < 10 Then
j = 1
Else
j = lngPageCount - 10
End If
For i = j To lngPageCount - 1
Response.Write("<a href=""?" & strQueryString & "&p=" & i & """>" & i & "</a> ")
Next
Response.Write(lPageCount)
Else '如果是中間的頁(yè)
If lngCurPage <= 5 Then
j = 1
Else
j = lngCurPage - 5
End If
If lngPageCount <= lngCurPage + 5 Then
k = lngPageCount
Else
k = lngCurPage + 5
End If
Response.Write("<a href=""?" & strQueryString & "&p=" & 1 & """>" & "<<" & "</a> ")
For i = j To lngCurPage - 1
Response.Write("<a href=""?" & strQueryString & "&p=" & i & """>" & i & "</a> ")
Next
Response.Write(lngCurPage & " ")
For i = lngCurPage + 1 To k
Response.Write("<a href=""?" & strQueryString & "&p=" & i & """>" & i & "</a> ")
Next
Response.Write(" <a href=""?" & strQueryString & "&p=" & lPageCount & """>" & ">>" & "</a>")
End If
End Sub
'********************
'函數(shù)作用:當(dāng)前頁(yè)請(qǐng)求方式是否為POST
'說明:用于在同一頁(yè)面處理顯示和數(shù)據(jù)操作,當(dāng)PostBack()為真時(shí)說明提交表單至當(dāng)前頁(yè),應(yīng)進(jìn)行數(shù)據(jù)后臺(tái)操作
Function PostBack()
If UCase(Trim(Request.ServerVariables("REQUEST_METHOD"))) = "POST" Then
PostBack = True
Else
PostBack = False
End If
End Function
'********************
'函數(shù)作用:返回執(zhí)行長(zhǎng)度的隨機(jī)字符串
'參數(shù):Length:長(zhǎng)度
Function GenRadomString(Length)
dim i, tempS, v
dim c(39)
tempS = ""
c(1) = "a": c(2) = "b": c(3) = "c": c(4) = "d": c(5) = "e": c(6) = "f": c(7) = "g"
c(8) = "h": c(9) = "i": c(10) = "j": c(11) = "k": c(12) = "l": c(13) = "m": c(14) = "n"
c(15) = "o": c(16) = "p": c(17) = "q": c(18) = "r": c(19) = "s": c(20) = "t": c(21) = "u"
c(22) = "v": c(23) = "w": c(24) = "x": c(25) = "y": c(26) = "z": c(27) = "1": c(28) = "2"
c(29) = "3": c(30) = "4": c(31) = "5": c(32) = "6": c(33) = "7": c(34) = "8": c(35) = "9"
If isNumeric(Length) = False Then
Response.Write "A numeric datatype was not submitted to this function."
Exit Function
End If
For i = 1 to Length
Randomize
v = Int((35 * Rnd) + 1)
tempS = tempS & c(v)
Next
GenRadomString = tempS
End Function
相關(guān)文章
asp 取得用戶真實(shí)IP,對(duì)代理地址仍然有效的函數(shù)
這篇文章主要介紹了asp 取得用戶真實(shí)IP,對(duì)代理地址仍然有效的函數(shù),需要的朋友可以參考下2007-08-08asp中的rs.open與conn.execute的區(qū)別說明
不管是rs.open sql,conn還是conn.execute(sql) [這里的SQL是delete,update,insert]執(zhí)行以后都會(huì)返回一個(gè)關(guān)閉的記錄集2011-01-01asp最簡(jiǎn)單最實(shí)用的計(jì)數(shù)器
asp最簡(jiǎn)單最實(shí)用的計(jì)數(shù)器...2007-09-09ASP下使用Access數(shù)據(jù)庫(kù)需要注意的18條安全法則
ASP下使用Access數(shù)據(jù)庫(kù)需要注意的18條安全法則,注意了下面地方,基本上您的access數(shù)據(jù)庫(kù)就不容易被別人盜取了。2011-02-02asp下將數(shù)據(jù)庫(kù)中的信息存儲(chǔ)至XML文件中
asp下將數(shù)據(jù)庫(kù)中的信息存儲(chǔ)至XML文件中...2007-04-04ASP把長(zhǎng)的數(shù)字用逗號(hào)隔開顯示的代碼
對(duì)于一些比較長(zhǎng)的數(shù)字,我們可以用asp實(shí)現(xiàn)隔開顯示,尤其是一些金錢相關(guān)的東西2008-06-06asp中回車換行符CHR(10)表示換行,CHR(13)表示回車,CHR(32)表示空格
這篇文章主要介紹了asp中回車換行符CHR(10)表示換行,CHR(13)表示回車,CHR(32)表示空格,需要的朋友可以參考下2006-08-08asp下tag的實(shí)現(xiàn),簡(jiǎn)單介紹與部分代碼
asp下tag的實(shí)現(xiàn),簡(jiǎn)單介紹與部分代碼...2007-03-03