Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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)

  • Leaders
Posted

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

[sIGPIC]e[/sIGPIC]
Posted

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

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...