Search and replace rich text without losing formatting

I am new to programming and need some help.

Im using VB 2010 express and Im trying to read the .rtf file for a string, then find and replace the text inside it and finally output as a new file

I managed to do this using the code below, BUT it loses formatting a carriage return, and the output is all on the same line?

thanks for any help james

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click

    Dim fileReader As String
    fileReader = My.Computer.FileSystem.ReadAllText("C:\Testing\Reports\test2.rtf")

    fileReader = fileReader.Replace("@@HCO@@", RichTextBox1.Text)

    Dim StreamW As New IO.StreamWriter("C:\Testing\Reports\test3.rtf")

    StreamW.Write(fileReader)
    StreamW.Close()
+4
source share
1 answer
RichTextBox1.Text 

does not contain formatting information. try instead:

RichTextBox1.Rtf

also the ReadAlltext function removes the missing cr. try ReadToEnd instead

+2
source

All Articles