再发几个ASP不错的函数
程序员文章站
2022-10-27 19:06:43
******************** '函数作用:根据条件真假返回选定值中的某个 '参数:blncondition:条件变量,varresulttrue:条件为真时返回...
********************
'函数作用:根据条件真假返回选定值中的某个
'参数:blncondition:条件变量,varresulttrue:条件为真时返回值,varresultfalse:条件为假时返回值
function iif(blncondition, varresulttrue,varresultfalse)
if cbool(blncondition) then
iif = varresulttrue
else
iif = varresultfalse
end if
end function
'********************
'函数作用:判断某个字符串元素是否在给定枚举中
'参数:sele:待判断的字符串,sarray:指定枚举
'举例:根据扩展名判断是否图片文件: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
'********************
'函数作用:判断某个字符串是否符合正则表达式
'参数:strstring:字符串,strpattern:正则表达式
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
'********************
'函数作用:正则提取
'参数:string:字符串,patrn:正则表达式
'返回:逗号分割的结果数组集成
function doreexec(strng,patrn)
dim regex, match, matches,retstr ' 创建变量。
set regex = new regexp ' 创建正则表达式。
regex.pattern = patrn ' 设置模式。
regex.ignorecase = true ' 设置为不区分大小写。
regex.global = true ' 设置全局适用。
set matches = regex.execute(strng) ' 执行搜索。
for each match in matches ' 对 matches 集合进行迭代。
retstr = retstr & match.value & "," & vbcrlf
next
doreexec = retstr
end function
复制代码 '********************
'函数作用:显示分页链接
'参数:lngcurpage:当前页是第几页,lngpagecount:一共几页,strsuerystring:分页链接需要附加的querystring变量
sub showpagenav(lngcurpage,lngpagecount,byval strquerystring)
response.write "当前第" & lngcurpage & "页,共:" & lngpagecount & "页"
dim i,j,k
if lngcurpage = 1 then '如果是第一页
'如果lngpagecount小于10,则导航页最多到lngpagecount页
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 '如果是最后一页
'如果lngpagecount小于10,则导航起始从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 '如果是中间的页
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
'********************
'函数作用:当前页请求方式是否为post
'说明:用于在同一页面处理显示和数据操作,当postback()为真时说明提交表单至当前页,应进行数据后台操作
function postback()
if ucase(trim(request.servervariables("request_method"))) = "post" then
postback = true
else
postback = false
end if
end function
'********************
'函数作用:返回执行长度的随机字符串
'参数:length:长度
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
'函数作用:根据条件真假返回选定值中的某个
'参数:blncondition:条件变量,varresulttrue:条件为真时返回值,varresultfalse:条件为假时返回值
function iif(blncondition, varresulttrue,varresultfalse)
if cbool(blncondition) then
iif = varresulttrue
else
iif = varresultfalse
end if
end function
'********************
'函数作用:判断某个字符串元素是否在给定枚举中
'参数:sele:待判断的字符串,sarray:指定枚举
'举例:根据扩展名判断是否图片文件: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
'********************
'函数作用:判断某个字符串是否符合正则表达式
'参数:strstring:字符串,strpattern:正则表达式
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
'********************
'函数作用:正则提取
'参数:string:字符串,patrn:正则表达式
'返回:逗号分割的结果数组集成
function doreexec(strng,patrn)
dim regex, match, matches,retstr ' 创建变量。
set regex = new regexp ' 创建正则表达式。
regex.pattern = patrn ' 设置模式。
regex.ignorecase = true ' 设置为不区分大小写。
regex.global = true ' 设置全局适用。
set matches = regex.execute(strng) ' 执行搜索。
for each match in matches ' 对 matches 集合进行迭代。
retstr = retstr & match.value & "," & vbcrlf
next
doreexec = retstr
end function
复制代码 '********************
'函数作用:显示分页链接
'参数:lngcurpage:当前页是第几页,lngpagecount:一共几页,strsuerystring:分页链接需要附加的querystring变量
sub showpagenav(lngcurpage,lngpagecount,byval strquerystring)
response.write "当前第" & lngcurpage & "页,共:" & lngpagecount & "页"
dim i,j,k
if lngcurpage = 1 then '如果是第一页
'如果lngpagecount小于10,则导航页最多到lngpagecount页
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 '如果是最后一页
'如果lngpagecount小于10,则导航起始从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 '如果是中间的页
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
'********************
'函数作用:当前页请求方式是否为post
'说明:用于在同一页面处理显示和数据操作,当postback()为真时说明提交表单至当前页,应进行数据后台操作
function postback()
if ucase(trim(request.servervariables("request_method"))) = "post" then
postback = true
else
postback = false
end if
end function
'********************
'函数作用:返回执行长度的随机字符串
'参数:length:长度
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
上一篇: 一上午抢我多少生意