StreamWriter loses format of existing text?


J

Jon Skeet [C# MVP]

Duckwon said:
I sent you zipped copies of the before and after file. I zipped the files
without ever opening them? so they are untouched.

And this time, lo and behold, when you look at them in a hex editor or
use a binary diff tool, we see that there is no difference between the
files until the place where the C# code started appending.
After that I opened the 'after' text file in a couple of other
editors (TextPad and Word). In those cases the text kept its format.
There is a font difference between the C++ text and the C# text. I
would prefer the text to be seamless.

The font and line ending differences are solely due to whatever the
editor chooses to do, based on a file that changes encoding half way
through.
When I open the same file in Notepad I still get the unformatted C++ text
(the first portion).

Sure - that's how it chooses to handle this problem.
This was with my original code, without your "Encoding.Unicode" fix.

Right - so the fix is the right one, it uses the same encoding for the
whole file. Now that we know it was notepad which was actually changing
the earlier contents of the file, there are no mysteries.
 
Ad

Advertisements

G

Guest

Jon Skeet said:
And this time, lo and behold, when you look at them in a hex editor or
use a binary diff tool, we see that there is no difference between the
files until the place where the C# code started appending.


The font and line ending differences are solely due to whatever the
editor chooses to do, based on a file that changes encoding half way
through.


Sure - that's how it chooses to handle this problem.


Right - so the fix is the right one, it uses the same encoding for the
whole file. Now that we know it was notepad which was actually changing
the earlier contents of the file, there are no mysteries.

Understood.
Thanks Jon!
 
W

Willy Denoyette [MVP]

Jon Skeet said:

Now that we know it was notepad which was actually changing
the earlier contents of the file, there are no mysteries.

True, but this happens only if you change the encoding in notepad when selecting "save as",
otherwise the file is not touched.
Which brings back the mystery as the OP said he did not save the file in Notepad.

Willy.
 
J

Jon Skeet [C# MVP]

Willy Denoyette said:
True, but this happens only if you change the encoding in notepad
when selecting "save as", otherwise the file is not touched.
Which brings back the mystery as the OP said he did not save the file
in Notepad.

No, he changed the filename when he sent me the files the first time.
The second time, he didn't save in Notepad and the file was untouched.
 
Ad

Advertisements

W

Willy Denoyette [MVP]

Jon Skeet said:
No, he changed the filename when he sent me the files the first time.
The second time, he didn't save in Notepad and the file was untouched.

Ok, mystery solved.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top