我试图删除文本文件中“X”行之后的所有行,我的意思是保留第一个“X”行并删除其余行。
我知道如何通过这种方式做到这一点:
1. Open the textfile
2. Read line by line
3. Count the line number.
4. Store the line content and append the string in the new textfile
5. Continue reading the next line and doing the same (step 3 & 4).
6. When line-count reaches "X" then stop reading lines.
太多的步骤和缓慢的方法,有人知道更好的改进(快速)方法来保留文本文件的前 1.000 行并删除其余行吗?
Private Sub Resize_LogFile()
If File.ReadAllLines(LogFile).Length > 1000 Then
' Delete all the lines after line number: 1.000
' Save it
End If
End Sub