bjwade62 Posted September 27, 2006 Posted September 27, 2006 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) Quote
Leaders snarfblam Posted September 27, 2006 Leaders Posted September 27, 2006 How are you saving the text? Quote [sIGPIC]e[/sIGPIC]
bjwade62 Posted September 27, 2006 Author Posted September 27, 2006 Here's what I'm doing. My.Computer.FileSystem.WriteAllText("c:\Temp\stmanplt.scr", TextBox1.Text, True) How are you saving the text? Quote
Administrators PlausiblyDamp Posted September 27, 2006 Administrators Posted September 27, 2006 How are you reading the text back? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Leaders snarfblam Posted September 27, 2006 Leaders Posted September 27, 2006 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: '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 Quote [sIGPIC]e[/sIGPIC]
bjwade62 Posted September 28, 2006 Author Posted September 28, 2006 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. 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: '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 Quote
Erel Posted September 29, 2006 Posted September 29, 2006 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.