问题描述
程序为ASP语言,如我需要截取某个页面中的username,和userpass,并保存为1.txt,且如有多个输入,就保存多行,格式为username1userpass1username2userpass2username3userpass3...................代码怎么写,请赐教
解决方案
解决方案二:
参考:<%Setfso=Server.CreateObject("Scripting.FileSystemObject")txt=server.mappath("1.txt")'保存信息的文件路径setwrtxt=fso.opentextfile(txt,8)'打开方式'wrtxt.atendofstream=""'FSOlinedittxt,2'Fso.DeleteFile(txt)wrtxt.Write("1")response.write("<b><fontcolor=red>Test</font></b><br><br>")'callwrite_txt(12,42)'callwrite_txt()subwrite_txt()response.write("<b><fontcolor=red>Test</font></b><br><br>")'wrtxt.writeline("shayoo")'写入源文件名'wrtxt.writeline'写一空行'wrtxt.writeline'写一空行whichfile=server.mappath("zl.txt")'设置源文件路径Setcnrs=fso.OpenTextFile(whichfile,1)'创建对象WhileNotcnrs.AtEndOfStream'读取文件内容rsline=cnrs.ReadLineResponse.Write(rsline&"<br>")'并分行显示行wrtxt.WriteLine(rsline)'分行写入文件Wend'循环endsub'读文件的某行functionFSOlinedit(filename,lineNum)iflinenum<1thenexitfunctiondimfso,f,temparray,tempcntsetfso=server.CreateObject("scripting.filesystemobject")ifnotfso.fileExists(filename)thenexitfunctionsetf=fso.opentextfile(filename,1)ifnotf.AtEndofStreamthentempcnt=f.readallf.closesetf=nothingtemparray=split(tempcnt,chr(13)&chr(10))iflineNum>ubound(temparray)+1thenexitfunctionelseFSOlinedit=temparray(lineNum-1)endifendifendfunction'写文件的某行functionFSOlinewrite(filename,lineNum,Linecontent)iflinenum<1thenexitfunctiondimfso,f,temparray,tempCntsetfso=server.CreateObject("scripting.filesystemobject")ifnotfso.fileExists(filename)thenexitfunctionsetf=fso.opentextfile(filename,1)ifnotf.AtEndofStreamthentempcnt=f.readallf.closetemparray=split(tempcnt,chr(13)&chr(10))iflineNum>ubound(temparray)+1thenexitfunctionelsetemparray(lineNum-1)=lineContentendiftempcnt=join(temparray,chr(13)&chr(10))setf=fso.createtextfile(filename,true)f.writetempcntendiff.closesetf=nothingendfunction'使用FSO删除文件内容的函数(未测试)FunctionDelLinetxt(file,line)DimstrTxt,MyFile,Fso,ionerrorresumenextSetFso=CreateObject("Scripting.FileSystemObject")SetMyFile=Fso.OpenTxtFile(file,1)i=0strTxt=""dowhilenotMyFile.AtEndOfLinei=i+1ifi=int(line)thenMyFile.ReadLineelsestrTxt=strTxt&MyFile.ReadLineendifloopMyFile.CloseFso.DeleteFile(file)SetMyFile=Fso.CreateTxtFile(file,true)MyFile.WritestrTxtMyFile.CloseSetMyFile=nothingSetFso=nothingiferr.number<>0thenDelLinetxt=falseelseDelLinetxt=trueendifEndFunction'使用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读取文件某一行的函数functionFSOlinedit1(filename,lineNum)iflinenum<1thenexitfunctiondimfso,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))iflineNum>ubound(temparray)+1thenexitfunctionelseFSOlinedit=temparray(lineNum-1)endifendifendfunction'使用FSO写文件某一行的函数functionFSOlinewrite(filename,lineNum,Linecontent)iflinenum<1thenexitfunctiondimfso,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))iflineNum>ubound(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%>