|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
1,读取文件中所有字符的函数 Function FSOFileRead(filename) filename = Server.mappath(filename) Set fso = Server.CreateObject("Scripting.FileSystemObject") if not fso.fileExists(filename) then exit function Set cnrs = fso.OpenTextFile(filename,1) While Not cnrs.AtEndOfStream rsline = cnrs.ReadLine rsline = server.HTMLEncode(rsline) Response.Write(rsline & "<br>") Wend end Function 其实就是通过ReadLine(读取行),通过 While Not cnrs.AtEndOfStream 的条件进行循环读取行,来达到读取文件中所有字符。当然也可以使用ReadAll代替多个ReadLine,但主要缺点是将格式进行换行等问题需要再次解决。 引用函数 call FSOFileRead("xxx文件") 即可 2,读取文件中某一行中所有字符的函数 Function FSOlinedit(filename,lineNum) if linenum < 1 then exit function filename = Server.mappath(filename) set fso = Server.CreateObject("Scripting.FileSystemObject") if not fso.fileExists(filename) then exit function set f = fso.opentextfile(filename,1) if not f.AtEndofStream then tempcnt = f.readall f.close set f = nothing temparray = split(tempcnt,chr(13)&chr(10)) if lineNum>ubound(temparray)+1 then exit function else FSOlinedit = temparray(lineNum-1) end if end if Response.Write(FSOlinedit) end Function 这次即使用了readall方式,通过split函数将读取的内容以换行为条件,进行数组的定义,提取 lineNum-1(数组从0记数) 所对应的数组值即为 读取的该行值 ,也就是该行中所有的字符了。 函数的调用 call FSOlinedit("xxx文件",35) 表示显示xxx文件的第35行内容 3,读取文件中最后一行内容的函数 Function FSOlastline(filename) filename = Server.mappath(filename) set fso = Server.CreateObject("Scripting.FileSystemObject") if not fso.fileExists(filename) then exit function set f = fso.opentextfile(filename,1) if not f.AtEndofStream then tempcnt = f.readall f.close set f = nothing temparray = split(tempcnt,chr(13)&chr(10)) FSOlastline = temparray(ubound(temparray)) end if Response.Write(FSOlastline) end function 其实和读取某一行的函数类似,主要即是 数组的上界ubound值 就是最末的值 ,故为最后一行。函数的引用也很简朴。 返回类别: 教程 上一教程: 页顶导航条示例 下一教程: 用XMLHTTP POST/GET HTML页面时的中文乱码之完全SCRIPT解决方案 您可以阅读与"FSO的几个应用函数"相关的教程: · ASP应用中的应用函数 · 关于session的几个补充函数 · 格式化数字函数FORMATNUMBER的应用 · 影响IIS性能的几个因素(3) · ASP.NET中处理datetime的一些通用函数 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |