overwriting a text file with text
overwriting a text file with text
well when ever i open a file and it contains a new line or when u press the
enter key that thing
i open files with the openfiledialog
when ever i overwrite a file those new line things come up as a box can somebody help
and im using vb 2005
heres a pic
enter key that thing
i open files with the openfiledialog
when ever i overwrite a file those new line things come up as a box can somebody help
and im using vb 2005
heres a pic
Last edited by Dagger13 on Sat Feb 02, 2008 11:47 am, edited 1 time in total.
(An Old one.)
-
- Posts: 5426
- Joined: Sat Jul 24, 2004 12:12 pm
- Location: I'm a Paranoid
- Contact:
For saving try this...simple:
Code: Select all
FileOpen(1,*FILEPATHTOSAVETO*, OpenMode.Output)
PrintLine(1, *textfieldcontainingthetext*)
FileClose(1)
...left for good
You can try this...
Code: Select all
richtextbox1.SaveFile(filename, RichTextBoxStreamType.PlainText)
It's just the way new lines are being saved by the two different methods.
The FileSystem method uses only the Line Feed (LF) control character, 0x0A, to represent a new line.. whereas notepad expects a Carriage Return (CR) control character, 0x0D, followed by a LF control character to represent a new line..
Without the CR, the LF goes unrecognised by Notepad, thus the unrecognised character..
The method Ant posted will use the CR+LF for new lines, so it'll "work" in Notepad.. but in future you're better off using the StreamWriter class for plain text operations.. in this case:
Although the rtb's built-in save method is obviously much more preferable here.
The FileSystem method uses only the Line Feed (LF) control character, 0x0A, to represent a new line.. whereas notepad expects a Carriage Return (CR) control character, 0x0D, followed by a LF control character to represent a new line..
Without the CR, the LF goes unrecognised by Notepad, thus the unrecognised character..
The method Ant posted will use the CR+LF for new lines, so it'll "work" in Notepad.. but in future you're better off using the StreamWriter class for plain text operations.. in this case:
Code: Select all
Dim sw As New StreamWriter(s.FileName)
For i As Integer = 0 To RichTextBox1.Lines.Length - 1
sw.WriteLine(RichTextBox1.Lines(i))
Next
sw.Close()
Halo 2 Prophet - Skin with ease with the simple 3D point and click interface.
Halo 3 Research Thread - Contribute to the research into Halo 3.
Halo 3 Research Thread - Contribute to the research into Halo 3.
-
- Posts: 5426
- Joined: Sat Jul 24, 2004 12:12 pm
- Location: I'm a Paranoid
- Contact: