Hello,
I'm writing a simple little solution to automatically edit a text doc based on a string. So far I have the app reading the file, finding the string, and writing a new file without the found string. I probably went about it the long way but it's working so I'm happy. But I'm open to any suggestion for streamlining (for some reason I just love stripping code to the absolute minimum number of characters possible).
So the string I'm looking for is actually represents a section in doc:
[Documents]
DOCVIEWER=Word Application
DOCVIEWER=Word Viewer
DOCVIEWER=RTF Viewer
To reiterate, the new doc is written with everything but [Documents]. What I would like to do now is have the next three lines omitted in the new doc to effectively remove the section.
Well, what I'm actually trying to accomplish is very simple. I just want to remove the above string (all four lines) from the target text file.
NOTE: The first line of the string [Documents] is a constant. However, the next three lines (it's always three) may vary. For instance one or more may be commented out with a semi-colon.
Module Module1
Sub Main()
Dim Reader As New IO.StreamReader("C:\ngconfig.ini")
Dim DataLines As New System.Collections.Specialized.StringCollection
Dim CurrentLine As String
Do While Reader.EndOfStream = False
CurrentLine = Reader.ReadLine
If CurrentLine.Contains("[Documents]") = False Then
DataLines.Add(CurrentLine)
End If
Loop
Reader.Close()
Reader = Nothing
Dim Writer As New IO.StreamWriter("C:\MyTest.txt")
For Each CurrentLine In DataLines
Writer.WriteLine(CurrentLine)
Next
Writer.Close()
Writer = Nothing
End Sub
End Module
Thanks in Advance!
dave
I'm writing a simple little solution to automatically edit a text doc based on a string. So far I have the app reading the file, finding the string, and writing a new file without the found string. I probably went about it the long way but it's working so I'm happy. But I'm open to any suggestion for streamlining (for some reason I just love stripping code to the absolute minimum number of characters possible).
So the string I'm looking for is actually represents a section in doc:
[Documents]
DOCVIEWER=Word Application
DOCVIEWER=Word Viewer
DOCVIEWER=RTF Viewer
To reiterate, the new doc is written with everything but [Documents]. What I would like to do now is have the next three lines omitted in the new doc to effectively remove the section.
Well, what I'm actually trying to accomplish is very simple. I just want to remove the above string (all four lines) from the target text file.
NOTE: The first line of the string [Documents] is a constant. However, the next three lines (it's always three) may vary. For instance one or more may be commented out with a semi-colon.
Module Module1
Sub Main()
Dim Reader As New IO.StreamReader("C:\ngconfig.ini")
Dim DataLines As New System.Collections.Specialized.StringCollection
Dim CurrentLine As String
Do While Reader.EndOfStream = False
CurrentLine = Reader.ReadLine
If CurrentLine.Contains("[Documents]") = False Then
DataLines.Add(CurrentLine)
End If
Loop
Reader.Close()
Reader = Nothing
Dim Writer As New IO.StreamWriter("C:\MyTest.txt")
For Each CurrentLine In DataLines
Writer.WriteLine(CurrentLine)
Next
Writer.Close()
Writer = Nothing
End Sub
End Module
Thanks in Advance!
dave