下面的代码是我最近正在整理的常用代码的一部分,陆续我将放出更多的实用代码,请大家把自己的代码回复,一边我整理,谢谢!
qq:393356
<%
判断文件名是否合法
function isfilename(afilename)
dim serrorstr,inamelength,i
isfilename=true
serrorstr=array("/","\",":","*","?","""","<",">","|")
inamelength=len(afilename)
if inamelength<1 or inamelength=null then
isfilename=false
else
for i=0 to 8
if instr(afilename,serrorstr(i)) then
isfilename=false
end if
next
end if
end function
去掉字符串头尾的连续的回车和空格
function trimvbcrlf(str)
trimvbcrlf=rtrimvbcrlf(ltrimvbcrlf(str))
end function
去掉字符串开头的连续的回车和空格
function ltrimvbcrlf(str)
dim pos,isblankchar
pos=1
isblankchar=true
while isblankchar
if mid(str,pos,1)=" " then
pos=pos+1
elseif mid(str,pos,2)=vbcrlf then
pos=pos+2
else
isblankchar=false
end if
wend
ltrimvbcrlf=right(str,len(str)-pos+1)
end function
去掉字符串末尾的连续的回车和空格
function rtrimvbcrlf(str)
dim pos,isblankchar
pos=len(str)
isblankchar=true
while isblankchar and pos>=2
if mid(str,pos,1)=" " then
pos=pos-1
elseif mid(str,pos-1,2)=vbcrlf then
pos=pos-2
else
isblankchar=false
end if
wend
rtrimvbcrlf=rtrim(left(str,pos))
end function
判断email是否有效,返回1表示正确
function isemail(aemail)
dim ilocat,v,ilength,i,checkletter
if instr(aemail,"@") = 0 or instr(aemail,".") = 0 then
isemail=0
exit function
end if
ilocat=instr(aemail,"@")
if instr(ilocat,aemail,".")=0 or instr(ilocat+1,aemail,"@")>0 then
isemail=0
exit function
end if
if left(aemail,1)="." or right(aemail,1)="." or left(aemail,1)="@" or right(aemail,1)="@" then
isemail=0
exit function
end if
v="1234567890abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz_-.@"
ilength=len(aemail)
for i=1 to ilength
checkletter=mid(aemail,i,1)
if instr(v,checkletter)=0 then
isemail=0
exit function
end if
next
isemail=1
end function
测试用:显示服务器信息
sub showserver
dim name
response.write "<table border=1 bordercolor=lightblue cellspacing=0>"
for each name in request.servervariables
response.write "<tr>"
response.write "<td>"&name&"</td>"
response.write "<td>"&request.servervariables(name)&"<br></td>"
response.write "</tr>"
next
response.write "</table>"
end sub
测试用:显示rs结果集以及字段名称
sub showrs(rs)
dim strtable,whatever
response.write "<center><table><tr>"
for each whatever in rs.fields
response.write "<td><b>" & whatever.name & "</b></td>"
next
strtable = "</tr><tr><td>"&rs.getstring(,,"</td><td>","</tr><tr><td>"," ") &"</td></tr></table></center>"
response.write(strtable)
end sub
用html格式显示文本
function txt2html(str)
if isnull(str) then
txt2html=""
exit function
end if
str=replace(str,chr(34),""")
str=replace(str,"<","<")
str=replace(str,">",">")
str=replace(str,chr(13)+chr(10),"<br>")
str=replace(str,chr(9)," ")
str=replace(str," "," ")
txt2html=str
end function
测试用:显示调试错误信息
sub showerror
dim serrmsg
serrmsg=err.source&" "&err.description
response.write "<center>"&serrmsg&"</center>"
err.clear
end sub
显示文字计数器
sub showcounter
dim fs,outfile,filename,count
filename=server.mappath("count.txt")
set fs = createobject("scripting.filesystemobject")
if fs.fileexists(filename) then
set outfile=fs.opentextfile(filename,1)
count=outfile.readline
count=count+1
response.write "<center>浏览人次:"&count&"<center>"
outfile.close
set outfile=fs.createtextfile(filename)
outfile.writeline(count)
else
set outfile=fs.opentextfile(filename,8,true)
count=0
outfile.writeline(count)
end if
outfile.close
set fs=nothing
end sub
%>
