VB中用OPEN语句修改文本文件
现在想实现比如有一个现成的TXT文件内容如下(假设为1.TXT):aaabbbcccddd想通过OPEN语句删除其中的ccc整行变成:aaabbbddd请问如何实现?...
现在想实现比如有一个现成的TXT文件内容如下(假设为1.TXT):
aaa
bbb
ccc
ddd
想通过OPEN语句删除其中的ccc整行
变成:
aaa
bbb
ddd
请问如何实现? 展开
aaa
bbb
ccc
ddd
想通过OPEN语句删除其中的ccc整行
变成:
aaa
bbb
ddd
请问如何实现? 展开
2个回答
展开全部
Private Sub Form_Load()
Dim content As String
Dim temp As String
Open "D:\1.txt" For Input As #1
Do Until EOF(1)
Input #1, temp
If temp = "ccc" Then 'CCC可以改成那行的内容
temp = ""
Else
temp = temp & vbCrLf
End If
content = content & temp
Loop
Close #1
Open "D:\1.txt" For Output As #1
Print #1, content
Close #1
End Sub
----------------
如果要指定要删除第几行的话可以定义一个常数,每读一行+1....
Dim content As String
Dim temp As String
Open "D:\1.txt" For Input As #1
Do Until EOF(1)
Input #1, temp
If temp = "ccc" Then 'CCC可以改成那行的内容
temp = ""
Else
temp = temp & vbCrLf
End If
content = content & temp
Loop
Close #1
Open "D:\1.txt" For Output As #1
Print #1, content
Close #1
End Sub
----------------
如果要指定要删除第几行的话可以定义一个常数,每读一行+1....
展开全部
Private Sub Command1_Click()
Dim a$, b$
Open "c:\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, a
If Trim(a) <> "ccc" Then b = b & a & vbCrLf
Loop
Close #1
Open "c:\1.txt" For Output As #1
Print #1, b
Close #1
MsgBox "搞定!"
End Sub
Dim a$, b$
Open "c:\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, a
If Trim(a) <> "ccc" Then b = b & a & vbCrLf
Loop
Close #1
Open "c:\1.txt" For Output As #1
Print #1, b
Close #1
MsgBox "搞定!"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询