I have written a program which reads the text from the text file cleans it for some specific letters or phrases and then saves it in another text file. I am having a problem in rewriting the processed or cleaned data (after it has removed some phrases and characters)onto writing the file.
I have successfully written the text on the file except one problem. In each loop when each string is cleaned and is written on the text file, it overwrites the previous string. What I want is that it should write in the next line or in the same line.
My code is given below:
Private Sub btnopen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnopen.Click FileOpen.Title = "Please select the file" FileOpen.InitialDirectory = "D:\" FileOpen.ShowDialog() Dim strm As System.IO.Stream strm = FileOpen.OpenFile Dim reader As New System.IO.StreamReader(strm) 'Dim FileName As String = "D:\tempfile.txt" Dim readline As String Do While reader.Peek() <> -1 readline = readline & reader.ReadLine & vbNewLine If readline.Contains("BAD") = True Then readline = Nothing Else 'Starting cleaning of ": FCS OK" at the end of the string Dim removecharacter As String = ": FCS OK" Dim cleanstring As String = Replace(readline, removecharacter, "") 'Writing the cleaned up data to the user mentioned text file Dim objwriter As New System.IO.StreamWriter("D:\" & FileName.Text & ".txt", False) objwriter.WriteLine(cleanstring) objwriter.Close() readline = Nothing End If Loop 'TextBox1.Text = readline If Not (strm Is Nothing) Then strm.Close() End If End Sub
Can anyone please tell me that how can I write the text in the new line and avoid overwriting of text in my text file.
Bilal A. Khan