VB 修改 TXT中指定的某一行?
比如有一个txt中有如下内容:AdapterTroubleshooter.exe>|1/294|38912|09:142009/July/14|||||ARP.EXE>|...
比如有一个txt中有如下内容:
AdapterTroubleshooter.exe>|1/294|38912|09:14 2009/July/14|||||
ARP.EXE>|2/294|20992|09:14 2009/July/14|||||
at.exe>|3/294|24064|09:14 2009/July/14|||||
AtBroker.exe>|4/294|29184|09:14 2009/July/14|||||
attrib.exe>|5/294|16384|09:14 2009/July/14|||||
auditpol.exe>|6/294|50176|09:14 2009/July/14|||||
AUTMGR32.EXE>|7/294|153088|00:00 1998/April/24|||||
autochk.exe>|8/294|668160|04:16 2010/November/20|||||
autoconv.exe>|9/294|679424|04:16 2010/November/20|||||
autofmt.exe>|10/294|658944|04:16 2010/November/20|||||
bitsadmin.exe>|11/294|186368|04:16 2010/November/20|||||
bootcfg.exe>|12/294|81408|09:14 2009/July/14|||||
我想修改
ARP.EXE>|2/294|20992|09:14 2009/July/14|||||
这行的内容,我应该如何修改?
ARP.EXE>|2/294|20992|09:14 2009/July/14|||||
不一定是第二行,是会变化的。
我已经能够根据关键字找到
ARP.EXE>|2/294|20992|09:14 2009/July/14|||||这行,请问如何修改?? 展开
AdapterTroubleshooter.exe>|1/294|38912|09:14 2009/July/14|||||
ARP.EXE>|2/294|20992|09:14 2009/July/14|||||
at.exe>|3/294|24064|09:14 2009/July/14|||||
AtBroker.exe>|4/294|29184|09:14 2009/July/14|||||
attrib.exe>|5/294|16384|09:14 2009/July/14|||||
auditpol.exe>|6/294|50176|09:14 2009/July/14|||||
AUTMGR32.EXE>|7/294|153088|00:00 1998/April/24|||||
autochk.exe>|8/294|668160|04:16 2010/November/20|||||
autoconv.exe>|9/294|679424|04:16 2010/November/20|||||
autofmt.exe>|10/294|658944|04:16 2010/November/20|||||
bitsadmin.exe>|11/294|186368|04:16 2010/November/20|||||
bootcfg.exe>|12/294|81408|09:14 2009/July/14|||||
我想修改
ARP.EXE>|2/294|20992|09:14 2009/July/14|||||
这行的内容,我应该如何修改?
ARP.EXE>|2/294|20992|09:14 2009/July/14|||||
不一定是第二行,是会变化的。
我已经能够根据关键字找到
ARP.EXE>|2/294|20992|09:14 2009/July/14|||||这行,请问如何修改?? 展开
3个回答
展开全部
XP+vb6测试通过
Private Sub Form_Load()
Dim m As String, a As String, t() As String
Open "c:\123.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, a
m = m & a & vbCrLf
Loop
Close #1
t = Split(m, vbCrLf)
For n = 0 To UBound(t)
If UCase(Left(t(n), 7)) = "ARP.EXE" Then
'在这里写你的处理过程
'下面是一个示例
t(n) = Replace(t(n), "ARP.EXE", "123.123")
End If
Next
m = Join(t, vbCrLf)
Open "c:\123.txt" For Output As #1
Print #1, m
Close #1
End Sub
Private Sub Form_Load()
Dim m As String, a As String, t() As String
Open "c:\123.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, a
m = m & a & vbCrLf
Loop
Close #1
t = Split(m, vbCrLf)
For n = 0 To UBound(t)
If UCase(Left(t(n), 7)) = "ARP.EXE" Then
'在这里写你的处理过程
'下面是一个示例
t(n) = Replace(t(n), "ARP.EXE", "123.123")
End If
Next
m = Join(t, vbCrLf)
Open "c:\123.txt" For Output As #1
Print #1, m
Close #1
End Sub
展开全部
假设你的文件名为“C:\a1.txt”
dim txt as string
Open "C:\a1.txt" for input as #1
Open "C:\a2.txt" for output as #2
do while not eof(1)
line input #1, txt
if txt="f=-50000" then txt="f="&Text1.Text
print #2,txt
loop
close
运行结束后,a2.txt中就是修改后的文件。
dim txt as string
Open "C:\a1.txt" for input as #1
Open "C:\a2.txt" for output as #2
do while not eof(1)
line input #1, txt
if txt="f=-50000" then txt="f="&Text1.Text
print #2,txt
loop
close
运行结束后,a2.txt中就是修改后的文件。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你可以先把全部内容读取过来,存入数组,可以是一行存为一个元素,然后判断哪一个符合条件,把想要替换的覆盖就行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询