vb txt1文件内容写入到txt2指定位置
将c:\txt1.txt的内容写入到c:\txt2.txt里的指定字符的下一行比如txt1的内容为12445323fdhfgffgfhy5fgj4446633txt2的内...
将c:\txt1.txt的内容写入到c:\txt2.txt里的指定字符的下一行
比如txt1的内容为
1244
5323
fdhfgf
fgfhy5fgj4
446633
txt2的内容为
098766544
09875533
<!>
08765433
456778hgf
97543gm
现在要把txt1的内容写入到txt2里的<!>下一行写入后把<!>这行删除
最终的结果如下:
098766544
09875533
1244
5323
fdhfgf
fgfhy5fgj4
446633
08765433
456778hgf
97543gm
请高手写下完整的代码 展开
比如txt1的内容为
1244
5323
fdhfgf
fgfhy5fgj4
446633
txt2的内容为
098766544
09875533
<!>
08765433
456778hgf
97543gm
现在要把txt1的内容写入到txt2里的<!>下一行写入后把<!>这行删除
最终的结果如下:
098766544
09875533
1244
5323
fdhfgf
fgfhy5fgj4
446633
08765433
456778hgf
97543gm
请高手写下完整的代码 展开
2个回答
展开全部
Dim strA() As String, strB() As String
ReDim strA(1), strB(1)
BX1 = "d:\txt1.txt"
BX2 = "d:\txt2.txt"
Open BX1 For Input As #1
Do While Not EOF(1)
Line Input #1, strA(UBound(strA))
ReDim Preserve strA(UBound(strA) + 1)
Loop
Close #1
Open BX2 For Input As #2
Do While Not EOF(2)
Line Input #2, strB(UBound(strB))
If InStr(1, strB(UBound(strB)), "<!>") > 0 Then
For n = 1 To UBound(strA) - 1
strB(UBound(strB)) = strA(n)
If n < UBound(strA) - 1 Then
ReDim Preserve strB(UBound(strB) + 1)
End If
Next
End If
ReDim Preserve strB(UBound(strB) + 1)
Loop
Close #2
ReDim strA(UBound(strB) - 2)
For n = 1 To UBound(strB) - 1
strA(n - 1) = strB(n)
Next
strs = Join(strA, vbCrLf)
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("d:\txt3.txt", True)
a.Write (strs)
a.Close
ReDim strA(1), strB(1)
BX1 = "d:\txt1.txt"
BX2 = "d:\txt2.txt"
Open BX1 For Input As #1
Do While Not EOF(1)
Line Input #1, strA(UBound(strA))
ReDim Preserve strA(UBound(strA) + 1)
Loop
Close #1
Open BX2 For Input As #2
Do While Not EOF(2)
Line Input #2, strB(UBound(strB))
If InStr(1, strB(UBound(strB)), "<!>") > 0 Then
For n = 1 To UBound(strA) - 1
strB(UBound(strB)) = strA(n)
If n < UBound(strA) - 1 Then
ReDim Preserve strB(UBound(strB) + 1)
End If
Next
End If
ReDim Preserve strB(UBound(strB) + 1)
Loop
Close #2
ReDim strA(UBound(strB) - 2)
For n = 1 To UBound(strB) - 1
strA(n - 1) = strB(n)
Next
strs = Join(strA, vbCrLf)
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("d:\txt3.txt", True)
a.Write (strs)
a.Close
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询