ASP实用函数库

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

%'判断文件名是否合法FunctionisFilename(aFilename)DimsErrorStr,iNameLength,iisFilename=TRUEsErrorStr=Array(/,\,:,*,?,,,,|)iNameLength=Len(aFilename)IfiNameLength1OriNameLength=nullThenisFilename=FALSEElseFori=0To8Ifinstr(aFilename,sErrorStr(i))ThenisFilename=FALSEEndIfNextEndIfEndFunction'去掉字符串头尾的连续的回车和空格functiontrimVBcrlf(str)trimVBcrlf=rtrimVBcrlf(ltrimVBcrlf(str))endfunction'去掉字符串开头的连续的回车和空格functionltrimVBcrlf(str)dimpos,isBlankCharpos=1isBlankChar=truewhileisBlankCharifmid(str,pos,1)=thenpos=pos+1elseifmid(str,pos,2)=VBcrlfthenpos=pos+2elseisBlankChar=falseendifwendltrimVBcrlf=right(str,len(str)-pos+1)endfunction'去掉字符串末尾的连续的回车和空格functionrtrimVBcrlf(str)dimpos,isBlankCharpos=len(str)isBlankChar=truewhileisBlankCharandpos=2ifmid(str,pos,1)=thenpos=pos-1elseifmid(str,pos-1,2)=VBcrlfthenpos=pos-2elseisBlankChar=falseendifwendrtrimVBcrlf=rtrim(left(str,pos))endfunction'判断Email是否有效,返回1表示正确FunctionisEmail(aEmail)DimiLocat,v,iLength,i,checkletterIfinstr(aEmail,@)=0Orinstr(aEmail,.)=0ThenisEmail=0EXITFUNCTIONEndIfiLocat=instr(aEmail,@)Ifinstr(iLocat,aEmail,.)=0Orinstr(iLocat+1,aEmail,@)0ThenisEmail=0EXITFUNCTIONEndIfIfleft(aEmail,1)=.Orright(aEmail,1)=.Orleft(aEmail,1)=@Orright(aEmail,1)=@ThenisEmail=0EXITFUNCTIONEndIfv=1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.@iLength=len(aEmail)Fori=1ToiLengthcheckletter=mid(aEmail,i,1)Ifinstr(v,checkletter)=0ThenisEmail=0EXITFUNCTIONEndIfNextisEmail=1EndFunction'测试用:显示服务器信息SubshowServerDimnameResponse.writeTableborder=1bordercolor=lightblueCELLSPACING=0foreachnameinrequest.servervariablesResponse.writetrResponse.writetd&name&/tdResponse.writetd&request.servervariables(name)&br/tdResponse.write/trnextResponse.write/tableEndSub'测试用:显示Rs结果集以及字段名称SubshowRs(rs)DimstrTable,whateverResponse.writecentertabletrforeachwhateverinrs.fieldsresponse.writetdb&whatever.name&/B/TDnextstrTable=/trtrtd&rs.GetString(,,/tdtd,/trtrtd,)&/td/tr/table/centerResponse.Write(strTable)EndSub'用HTML格式显示文本Functiontxt2Html(str)ifisnull(str)thentxt2Html=exitFunctionendifstr=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=strEndFunction'测试用:显示调试错误信息SubshowErrorDimsErrMsgsErrMsg=Err.Source&&Err.DescriptionResponse.writecenter&sErrMsg&/centerErr.clearEndSub'显示文字计数器SubshowCounterDimfs,outfile,filename,countfilename=server.mappath(count.txt)Setfs=CreateObject(Scripting.FileSystemObject)Iffs.fileExists(filename)ThenSetoutfile=fs.openTextFile(filename,1)count=outfile.readlinecount=count+1Response.writecenter浏览人次:&count¢eroutfile.closeSetoutfile=fs.CreateTextFile(filename)outfile.writeline(count)ElseSetoutfile=fs.openTextFile(filename,8,TRUE)count=0outfile.writeline(count)ENDIFoutfile.closesetfs=nothingEndSub%Array()FUNCTION:返回一个数组SYNTAX:Array(list)ARGUMENTS:字符,数字均可EXAMPLE:%DimmyArray()Fori=1to7RedimPreservemyArray(i)myArray(i)=WeekdayName(i)Next%RESULT:建立了一个包含7个元素的数组myArraymyArray(Sunday,Monday,......Saturday)CInt()FUNCTION:将一个表达式转化为数字类型SYNTAX:CInt(expression)ARGUMENTS:任何有效的字符均可EXAMPLE:%f=234response.writecINT(f)+2%RESULT:236转化字符234为数字234,如果字符串为空,则返回0值CreateObject()FUNCTION:建立和返回一个已注册的ACTIVEX组件的实例。SYNTAX:CreateObject(objName)ARGUMENTS:objName是任何一个有效、已注册的ACTIVEX组件的名字.EXAMPLE:%Setcon=Server.CreateObject(ADODB.Connection)%RESULT:CStr()FUNCTION:转化一个表达式为字符串.SYNTAX:CStr(expression)ARGUMENTS:expression是任何有效的表达式。EXAMPLE:%s=3+2response.writeTheresultis:&cStr(s)%RESULT:转化数字“5”为字符“5”。Date()FUNCTION:返回当前系统日期.SYNTAX:Date()ARGUMENTS:None.EXAMPLE:%=Date%RESULT:8/4/99DateAdd()FUNCTION:返回一个被改变了的日期。SYNTAX:DateAdd(timeinterval,number,date)ARGUMENTS:timeintervalisthetimeintervaltoadd;numberisamountoftimeintervalstoadd;anddateisthestartingdate.EXAMPLE:%currentDate=#8/4/99#newDate=DateAdd(m,3,currentDate)response.writenewDate%%currentDate=#12:34:45PM#newDate=DateAdd(h,3,currentDate)response.writenewDate%RESULT:11/4/993:34:45PMm=month;d=day;IfcurrentDateisintimeformatthen,h=hour;s=second;DateDiff()FUNCTION:返回两个日期之间的差值。SYNTAX:DateDiff(timeinterval,date1,date2[,firstdayofweek][,firstweekofyear]])ARGUMENTS:timeinterval表示相隔时间的类型,如“M“表示“月”。EXAMPLE:%fromDate=#8/4/99#toDate=#1/1/2000#response.writeThereare&_DateDiff(d,fromDate,toDate)&_daystomilleniumfrom8/4/99.%RESULT:从8/4/99到2000年还有150天.Day()FUNCTION:返回一个月的第几日.SYNTAX:Day(date)ARGUMENTS:date是任何有效的日期。EXAMPLE:%=Day(#8/4/99#)%RESULT:4FormatCurrency()FUNCTION:返回表达式,此表达式已被格式化为货币值SYNTAX:FormatCurrency(Expression[,Digit][,LeadingDigit][,Paren][,GroupDigit]]]])ARGUMENTS:Digit指示小数点右侧显示位数的数值。默认值为-1,指示使用的是计算机的区域设置;LeadingDigit三态常数,指示是否显示小数值小数点前面的零。EXAMPLE:%=FormatCurrency(34.3456)%RESULT:$34.35FormatDateTime()FUNCTION:返回表达式,此表达式已被格式化为日期或时间SYNTAX:FormatDateTime(Date,[,NamedFormat])ARGUMENTS:NamedFormat指示所使用的日期/时间格式的数值,如果省略,则使用vbGeneralDate.EXAMPLE:%=FormatDateTime(08/4/99,vbLongDate)%RESULT:Wednesday,August04,1999FormatNumber()FUNCTION:返回表达式,此表达式已被格式化为数值.SYNTAX:FormatNumber(Expression[,Digit][,Lead

1 / 38
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功