vb 读取并插入到txt文本的的末尾(或指定位置)一组字符串的问题
vb 读取并插入到txt文本的的末尾(或指定位置)一组字符串的问题
如在1.txt (123,456,789
741,852,963)两行(格式固定)
如果我想在789后面追加 :159
或在852,后面加一个数据:753
该如何处理呢?
谢谢大虾们!
[解决办法]
Private Sub Command1_Click()
Dim sys As New FileSystemObject
Dim f As TextStream
Set f = sys.OpenTextFile( "c:\eeee.txt ", ForReading)
Dim i As Integer
i = 0
While Not (f.AtEndOfLine)
Debug.Print f.ReadLine
i = i + 1
Wend
Dim s() As String
ReDim s(i)
f.Close
Set f = sys.OpenTextFile( "c:\eeee.txt ", ForReading)
i = 0
While Not (f.AtEndOfLine)
s(i) = f.ReadLine
If (i = 1) Then
s(i) = s(i) + "223344 "
End If
i = i + 1
Wend
f.Close
Set f = sys.OpenTextFile( "c:\eeee.txt ", ForWriting)
For j = 0 To i
f.WriteLine (s(j))
Next
f.Close
End Sub
[解决办法]
open 打开
line输入
Replace函数替换
'(也就是就是说如果在852后面加753就写成Replace(linestr, "852 ", "852,753 "))
close 关闭
完事了.要我说就这点事