LabRat
LabRat

Reputation: 2014

rich textbox combines all lines into one when saved as txt file?

I have a rich textbox in vb.net, which contains several lines of text however when I try and save the text to a .txt file all the lines are combined into one???

How can I overcome this?

what i did try was:

       Dim MYLINES As Object

        For Each MYLINES In RichTextBox1.Text
        objWriter.WriteLine(MYLINES.ToString & Environment.NewLine)
    Next

objWriter.Close()

however this simply placed every single character on a difrent line...

Upvotes: 0

Views: 2159

Answers (1)

SysDragon
SysDragon

Reputation: 9888

Save it as a .RTF file (instead of .TXT), wich can process the line breaks directly. Thats an option.

Or you can wirte the lines individually:

Dim sw As New System.IO.StreamWriter(sFileName)

For Each sLine as String in TextBox1.Lines
    sw.WriteLine(sLine)
Next

sw.Close()

The method WriteLine already adds a line break at the end. It more or less the same as:

 .Write(sLine & Enviroment.NewLine())

Upvotes: 1

Related Questions