VB,ASP读写文本文件及读取指定行
来源:互联网 发布:js给href赋参数值 编辑:程序博客网 时间:2024/04/30 20:17
写文本的代码
- <%
- set myfileobject=server.CreateObject("Scripting.FileSystemObject")
- set mytextfile=myfileobject.OpenTextFile(server.MapPath("test.txt"),2,true)
- mytextfile.WriteLine("这是一个测试")
- mytextfile.WriteLine("这是一个测试")
- mytextfile.close
- %>
读文本的代码:
- <%
- set myfileobject=server.createobject("scripting.filesystemobject")
- set mytextfile=myfileobject.opentextfile("c:/mydir/test.txt")
- while not mytextfile.atendofstream
- response.write(mytextfile.readline)
- wend
- mytextfile.close
- %>
上面的读取方式显然有些原始,看下面:
优化后的读取指文本文件定行的函数代码
- Function lines(txtpath As String, ByVal startline As Integer, linenum As Integer) As String '显示 txtpath 文件的从startline 行开始的 linenum 行的内容
- lines = ""
- Dim filetxt As String, x As Variant, i As Integer
- filetxt = String(FileLen(txtpath), " ")
- Open txtpath For Binary As 1
- Get #1, , filetxt
- Close 1
- x = Split(filetxt, vbCrLf)
- 'MsgBox UBound(x) + 1 '行数
- If startline > UBound(x) Then MsgBox "行溢出", 64, "err!": Exit Function
- If startline <= UBound(x) Then
- If startline + linenum <= UBound(x) Then
- For i = startline To startline + linenum - 1
- lines = lines & x(i) & " "
- Next
- Else
- For i = startline To UBound(x)
- lines = lines & x(i) & " "
- Next
- End If: End If
- End Function
- VB,ASP读写文本文件及读取指定行
- vb中读写文本文件
- VB 读写UTF8文本文件
- 嵌入式 linux读取按行读写文本文件
- 读写文本文件 ---字符行式读取
- linux读取按行读写文本文件
- linux读取按行读写文本文件
- vb 读取文件指定行
- java语言读取文本文件的指定行
- C#从文本文件读取指定行
- java语言读取文本文件的指定行
- VB.NET读写文本文件方法
- asp读取文本文件
- vb.net读取文本文件函数
- VB读取文本文件的例子:逐行读取
- ASP 如何读写一个文本文件
- Matlab从指定行读取文本文件(textscan)
- 文本文件读取和二进制文件读写的区别
- 做研究
- extract SQL statements from Java source
- SQL Server数据库性能优化
- Atom vs RSS
- JBoss4在MyEclipse中无法启动的一个解决方法
- VB,ASP读写文本文件及读取指定行
- 操作ini文件
- Squidoo--每月在不花一分钱的情况下赚得数千美元!
- 05级市场营销(本)作业
- IT专业人士必去得10个社区
- .net的广告组件开源
- 创建和管理表
- Squidoo:人人都是专家
- MySQL数据库的复制与修复