VB读取文本文件特定的内容,然后进行修改
有个text1文本框,一个按纽现在c盘下有一个1.txt文本文件,文件里有三行文字.<csr>1987</csr><qqw>198</qqw><csrqq>20</csr...
有个text1文本框,一个按纽
现在c盘下有一个1.txt文本文件, 文件里有三行文字.
<csr>1987</csr>
<qqw>198</qqw>
<csrqq>20</csrqq>
前面的空格是按两个tab的,不是空格.
现在我要修改<csrqq>那行的东西.想把text1.text里面的内容到<csrqq>跟</csrqq>之间,也就是<csrqq>text1.text</csrqq>,万分感谢解答 展开
现在c盘下有一个1.txt文本文件, 文件里有三行文字.
<csr>1987</csr>
<qqw>198</qqw>
<csrqq>20</csrqq>
前面的空格是按两个tab的,不是空格.
现在我要修改<csrqq>那行的东西.想把text1.text里面的内容到<csrqq>跟</csrqq>之间,也就是<csrqq>text1.text</csrqq>,万分感谢解答 展开
2个回答
展开全部
Private Sub Command1_Click()
Open "c:\1.txt" For Input As #1
Open "c:\2.txt" For Output As #2
Do While Not EOF(1)
Line Input #1, s
If InStr(1, s, "<csrqq>") > 0 Then
d1 = InStr(1, s, "<csrqq>")
d2 = InStr(d1 + 1, s, "<") - 1
s = Left(s, d1 + 6) & Text1.Text & Right(s, Len(s) - d2)
End If
Print #2, s
Loop
Close #1
Close #2
End Sub
Open "c:\1.txt" For Input As #1
Open "c:\2.txt" For Output As #2
Do While Not EOF(1)
Line Input #1, s
If InStr(1, s, "<csrqq>") > 0 Then
d1 = InStr(1, s, "<csrqq>")
d2 = InStr(d1 + 1, s, "<") - 1
s = Left(s, d1 + 6) & Text1.Text & Right(s, Len(s) - d2)
End If
Print #2, s
Loop
Close #1
Close #2
End Sub
展开全部
写为另一个文件:
Private Sub Command1_Click()
Dim iFreein As Integer, iFreeout As Integer, sLine As String
iFreein = FreeFile
Open "c:\1.txt" For Input As #iFreein
iFreeout = FreeFile
Open "c:\2.txt" For Output As #iFreeout
While Not EOF(iFreein)
Line Input #iFreein, sLine
If InStr(sLine, "<csrqq>20</csrqq>"<> 0 Then
sLine = Replace(sLine, "20", text1.text)
End If
Print #iFreeout, sLine
Wend
Close
End Sub
Private Sub Command1_Click()
Dim iFreein As Integer, iFreeout As Integer, sLine As String
iFreein = FreeFile
Open "c:\1.txt" For Input As #iFreein
iFreeout = FreeFile
Open "c:\2.txt" For Output As #iFreeout
While Not EOF(iFreein)
Line Input #iFreein, sLine
If InStr(sLine, "<csrqq>20</csrqq>"<> 0 Then
sLine = Replace(sLine, "20", text1.text)
End If
Print #iFreeout, sLine
Wend
Close
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询