|
-
Mar 27th, 2006, 08:15 AM
#1
[RESOLVED] 2k5 StreamWriter problem
When I write out to a file, 3 weird characters are appended to the beginning of it. When I look at the string, or the bytes in the immediate window, I just see the normal characters that I would expect. Anybody else hit this problem? If so, is there a solution?
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 27th, 2006, 08:55 AM
#2
Re: 2k5 StreamWriter problem
Which characters are acting like that? Any character?
Your code looks like this?
VB Code:
Dim sw As StreamWriter = New StreamWriter("C:\MyFile.txt")
sw.Write("!·$%&/()=»)12345678" & vbNewLine)
sw.Close()
sw = Nothing
-
Mar 27th, 2006, 09:02 AM
#3
Re: 2k5 StreamWriter problem
-
Mar 27th, 2006, 09:03 AM
#4
Re: 2k5 StreamWriter problem
Its not that its changing characters, its prepending them to the beginning of the string that I write to the file.
My code looks pretty much like this...
Code:
Dim sw As StreamWriter = My.Computer.FileSystem.OpenTextFileWriter("c:\test.txt")
sw.WriteLine(someText)
sw.Close()
They are the same characters everytime I run it, and they don't show up when you view the text file through notepad, or even VS. But if you look at it in hex, you see them.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 27th, 2006, 09:13 AM
#5
Re: 2k5 StreamWriter problem
Well if it's Unicode then what you are seeing is almost certainly the Byte Order Mark, which is prepended to most Unicode files. The BOM dictates whether the characters should be read in little-endian or big-endian format.
-
Mar 27th, 2006, 09:15 AM
#6
Re: 2k5 StreamWriter problem
By default OpenTextFileWriter should use ASCII encoding, as it's explained here, but as Penagate said, thats a common behavior of Unicode. Try setting the 3rd parameter of OpenTextFileWriter to unicode.
Last edited by jcis; Mar 27th, 2006 at 09:23 AM.
-
Mar 27th, 2006, 09:40 AM
#7
Re: 2k5 StreamWriter problem
It shouldn't be unicode, though. There are no extended characters in the text. There should be no problem writing it as ASCII.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|