Why are these  charactors in my saved textbox file?

bjwade62

Centurion
Joined
Oct 31, 2003
Messages
104
The first line of the saved file from a textbox contain these charactors . Why are they there and do I stop them from happening?

Example: (setvar "sdi" 1)

What I want is: (setvar "sdi" 1)
 
That last parameter (the true)...

My.Computer.FileSystem.WriteAllText("c:\Temp\stmanplt.scr", TextBox1.Text, True)

is the Append parameter. If you append text to a file you will add the text onto what is already there. Is it possible that the extraneous characters were already in the file? Another possibility (I'm not sure, I've never used the "My" feature) is that the extraneous characters are a length prefix (i.e. data written to the file to specify how long a string is, and not meant to be viewed as text.

If this is not the case, a simple solution would be to use the more .Net-friendly (i.e. compatible with all .Net languages) and proven approach of using a StreamWriter:
Visual Basic:
'This method will write (or append) the specified text to a text file
Public Shared Sub WriteToFile(file As String, text As String, append As Boolean) {
    Dim writer As StreamWriter = new StreamWriter(file, append)
    writer.Write(text)
    writer.Close()
End Sub
 
All that and it was the app I was using to read the saved file in. It's a lisp editor for AutoCAD. It looks fine in everything else, word, wordpad, notepad...


Thanks anyway.



marble_eater said:
That last parameter (the true)...

My.Computer.FileSystem.WriteAllText("c:\Temp\stmanplt.scr", TextBox1.Text, True)

is the Append parameter. If you append text to a file you will add the text onto what is already there. Is it possible that the extraneous characters were already in the file? Another possibility (I'm not sure, I've never used the "My" feature) is that the extraneous characters are a length prefix (i.e. data written to the file to specify how long a string is, and not meant to be viewed as text.

If this is not the case, a simple solution would be to use the more .Net-friendly (i.e. compatible with all .Net languages) and proven approach of using a StreamWriter:
Visual Basic:
'This method will write (or append) the specified text to a text file
Public Shared Sub WriteToFile(file As String, text As String, append As Boolean) {
    Dim writer As StreamWriter = new StreamWriter(file, append)
    writer.Write(text)
    writer.Close()
End Sub
 
These 3 characters are Unicode BOM characters.
It tells text editors which unicode format the file uses.
To avoid these characters, save the file encoded as ASCII.
Most editors won't show the BOM but some will show it.
 
Back
Top