您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > 数据库 > ASP的自定义实用函数表(2)
ASP的自定义实用函数表(2)2004-9-247:19:00作者:模板天下收集整理来源:未知网友评论0条论坛'CFS編碼加密FunctionCfsEnCode(CodeStr)DimCodeLenDimCodeSpaceDimNewCodeCodeLen=30CodeSpace=CodeLen-Len(CodeStr)IfNotCodeSpace1ThenForcecr=1ToCodeSpaceCodeStr=CodeStr&Chr(21)NextEndIfNewCode=1DimBeenForcecb=1ToCodeLenBeen=CodeLen+Asc(Mid(CodeStr,cecb,1))*cecbNewCode=NewCode*BeenNextCodeStr=NewCodeNewCode=EmptyForcec=1ToLen(CodeStr)NewCode=NewCode&CfsCode(Mid(CodeStr,cec,3))NextForcec=20ToLen(NewCode)-18Step2CfsEnCode=CfsEnCode&Mid(NewCode,cec,1)NextEndFunctionFunctionCfsCode(Word)Forcc=1ToLen(Word)CfsCode=CfsCode&Asc(Mid(Word,cc,1))NextCfsCode=Hex(CfsCode)EndFunction編碼函式CfsEncode()的使用:Var=CfsEncode(字串來源)範例:%DimSourceDimVar1Source=testVar1=CfsEncode(Source)Response.WriteVar1%-------------------------------------------用正则表达式写的HTML分离函数存成.asp文件,执行,你用ASPHTTP抓内容的时候用这个很爽,当然自己要改进一下了%OptionExplicitFunctionstripHTML(strHTML)'StripstheHTMLtagsfromstrHTMLDimobjRegExp,strOutputSetobjRegExp=NewRegexpobjRegExp.IgnoreCase=TrueobjRegExp.Global=TrueobjRegExp.Pattern=.+?'ReplaceallHTMLtagmatcheswiththeemptystringstrOutput=objRegExp.Replace(strHTML,)'ReplaceallandwithandstrOutput=Replace(strOutput,,)strOutput=Replace(strOutput,,)stripHTML=strOutput'ReturnthevalueofstrOutputSetobjRegExp=NothingEndFunction%formmethod=postid=form1name=form1bEnteranHTMLString:/bbrtextareaname=txtHTMLcols=50rows=8wrap=virtual%=Request(txtHTML)%/textareapinputtype=submitvalue=StripHTMLTags!id=submit1name=submit1/form%ifLen(Request(txtHTML))0then%phrpbuViewofstringiwithno/iHTMLstripping:/u/bbrxmp%=Request(txtHTML)%/xmppbuViewofstringiwith/iHTMLstripping:/u/bbrpre%=StripHTML(Request(txtHTML))%/pre%EndIf%---------------------------------------如何检测备注字段的字节数视服务器操作系统语种不同,而采取不同的方法:1.E文下,len(rs(field)),就行了.len(中文abc)=72.Z文下,复杂一点,len(中文abc)=5lenB(中文abc)=10,所以需要自己写程序判断其长度.functionstrLen(str)dimi,l,t,cl=len(str)t=lfori=1tolc=asc(mid(str,i,1))ifc0thenc=c+65536ifc255thent=t+1endifnextstrLen=tendfunction------------------------------------FSO自写自用的几个函数''''使用FSO修改文件特定内容的函数functionFSOchange(filename,Target,String)DimobjFSO,objCountFile,FiletempDataSetobjFSO=Server.CreateObject(Scripting.FileSystemObject)SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)FiletempData=objCountFile.ReadAllobjCountFile.CloseFiletempData=Replace(FiletempData,Target,String)SetobjCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)objCountFile.WriteFiletempDataobjCountFile.CloseSetobjCountFile=NothingSetobjFSO=NothingEndFunction''''使用FSO读取文件内容的函数functionFSOFileRead(filename)DimobjFSO,objCountFile,FiletempDataSetobjFSO=Server.CreateObject(Scripting.FileSystemObject)SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)FSOFileRead=objCountFile.ReadAllobjCountFile.CloseSetobjCountFile=NothingSetobjFSO=NothingEndFunction''''使用FSO读取文件某一行的函数functionFSOlinedit(filename,lineNum)iflinenum1thenexitfunctiondimfso,f,temparray,tempcntsetfso=server.CreateObject(scripting.filesystemobject)ifnotfso.fileExists(server.mappath(filename))thenexitfunctionsetf=fso.opentextfile(server.mappath(filename),1)ifnotf.AtEndofStreamthentempcnt=f.readallf.closesetf=nothingtemparray=split(tempcnt,chr(13)&chr(10))iflineNumubound(temparray)+1thenexitfunctionelseFSOlinedit=temparray(lineNum-1)endifendifendfunction''''使用FSO写文件某一行的函数functionFSOlinewrite(filename,lineNum,Linecontent)iflinenum1thenexitfunctiondimfso,f,temparray,tempCntsetfso=server.CreateObject(scripting.filesystemobject)ifnotfso.fileExists(server.mappath(filename))thenexitfunctionsetf=fso.opentextfile(server.mappath(filename),1)ifnotf.AtEndofStreamthentempcnt=f.readallf.closetemparray=split(tempcnt,chr(13)&chr(10))iflineNumubound(temparray)+1thenexitfunctionelsetemparray(lineNum-1)=lineContentendiftempcnt=join(temparray,chr(13)&chr(10))setf=fso.createtextfile(server.mappath(filename),true)f.writetempcntendiff.closesetf=nothingendfunction''''使用FSO添加文件新行的函数functionFSOappline(filename,Linecontent)dimfso,fsetfso=server.CreateObject(scripting.filesystemobject)ifnotfso.fileExists(server.mappath(filename))thenexitfunctionsetf=fso.opentextfile(server.mappath(filename),8,1)f.writechr(13)&chr(10)&Linecontentf.closesetf=nothingendfunction''''读文件最后一行的函数functionFSOlastline(filename)dimfso,f,temparray,tempcntsetfso=server.CreateObject(scripting.filesystemobject)ifnotfso.fileExists(server.mappath(filename))thenexitfunctionsetf=fso.opentextfile(server.mappath(filename),1)ifnotf.AtEndofStreamthentempcnt=f.readallf.closesetf=nothingtemparray=split(tempcnt,chr(13)&chr(10))FSOlastline=temparray(ubound(temparray))endifendfunction还有,创建文件夹:subCreateFolder(Foldername)Setafso=Server.CreateObject(Scripting.FileSystemObject)ifafso.folderexists(server.mappath(Foldername))=truethenelseafso.createfolder(server.mappath(foldername))endifsetafso=nothingendsub用法,createfolder(foldername)----------------------------------------''检查字符串是否包含非法字符串FUNCTIONBadWords(strContent)DIMobjRegExpSetobjRegExp=newRegExpobjRegExp.Ign
本文标题:ASP的自定义实用函数表(2)
链接地址:https://www.777doc.com/doc-6371280 .html