Group,
I'm now having to merge several of these text files together. At the end of each of the text files is a line that says "End of Report". I need to eliminate this line completely.
This code does the merge for me:
RestranName = getRestranName(0)
RestranName2 = getRestranName(1)
System.IO.File.AppendAllText(RestranName2, System.IO.File.ReadAllText(RestranName))
These files are UNIX created and are unformated. So I'm using the following code to format it correctly:
' This reads the text file for conversion
txtLine = My.Computer.FileSystem.ReadAllText(RestranName)
' This begins to add the carriage returns in the appropriate places
txtLine = Replace(txtLine, vbLf, vbCrLf)
txtLine = Replace(txtLine, vbCr & vbCr, vbCr)
txtLine = Replace(txtLine, """", "")
' This writes the line to the file
My.Computer.FileSystem.WriteAllText(fileSave, txtLine, False)
This works perfectly. Unfortunately though I have "End of Report" between the two merged and formatted reports. I've got to figure out how to remove those words and the line (or spaces around it).
I've tried using StreamWriter to read the unformated but merged file (RestranName) to find the "End of Report" line using this code:
Using reader As New StreamReader(RestranName)
While Not reader.EndOfStream
Dim line As String = reader.ReadLine()
If line.Contains("End of Report") Then
badLine = line
Else
goodLine = line
My.Computer.FileSystem.WriteAllText(RestranName2, goodLine, True)
End If
End While
End Using
This works to remove the line that includes "End of Report". Unfortunately when it goes through the routine for formatting, it doesn't do it correctly. Any thoughts as to why? Any idea how to fix?
Thanks,
Don