比如c:\1.txt
a
b
c
我要删除第2行返回
a
c
或我要添加第2行,添加数据是*,返回
a
*
b
c
谁给写个简洁点的Function吧
a
b
c
我要删除第2行返回
a
c
或我要添加第2行,添加数据是*,返回
a
*
b
c
谁给写个简洁点的Function吧
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
DeleteLine "c:\1.txt", 2
InsertLine "c:\1.txt", 2, "*"
Sub DeleteLine(filespec, rownum)
Dim fso, f, temp, i
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filespec, 1)
temp = ""
i = 0
While Not f.AtEndOfStream
i = i + 1
If Not i = rownum Then
temp = temp & f.ReadLine & vbCrLf
Else
f.SkipLine
End If
WEnd
f.Close
Set f = fso.OpenTextFile(filespec, 2)
f.Write temp
f.Close
End Sub
Sub InsertLine(filespec, rownum, oneline)
Dim fso, f, temp, i
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filespec, 1)
temp = ""
i = 0
While Not f.AtEndOfStream
i = i + 1
If i = rownum Then temp = temp & oneline & vbCrLf
temp = temp & f.ReadLine & vbCrLf
WEnd
f.Close
Set f = fso.OpenTextFile(filespec, 2)
f.Write temp
f.Close
End Sub