I have a simple script that deletes the first n lines of a text file.
Const FOR_READING = 1
Const FOR_WRITING = 2
strFileName = "C:\scripts\test.txt"
iNumberOfLinesToDelete = 5
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objTS = objFS.OpenTextFile(strFileName, FOR_READING)
strContents = objTS.ReadAll
objTS.Close
arrLines = Split(strContents, vbNewLine)
Set objTS = objFS.OpenTextFile(strFileName, FOR_WRITING)
For i=0 To UBound(arrLines)
If i > (iNumberOfLinesToDelete - 1) Then
objTS.WriteLine arrLines(i)
End If
Next
I would like to ask if there is a way if you only have a specific line in the text file which you only want to delete? Meaning based on the line number of the text file.
For example,
1
2
This is line 3
4
5
And you want to remove line number 3. Specifically line number 3.
Result:
1
2
4
5
Is there a way on how to do it?
A big appreciation for the answer and the help.