space character / streamwriter problem C#
I 开发者_运维技巧tried to make a fixed width file, but I found that when I use the space character I have a strange signs in my txt file. If I change the "50" number to something like "15" or "1000", it works fine.
This is my code:
string fileName = Path.GetTempPath() + "temp.txt";
FileStream stream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter writer = new StreamWriter(stream);
writer.Write("1".PadRight(50, ' '));
writer.Write("0".PadRight(756, ' '));
writer.Close();
What is wrong?
Disregard what you read here previously. I took the output of your program, which does shows up strange in Microsoft Notepad, and opened it in a few other editors. It appears fine in all of them. Convinced it was some encoding error, I then cracked open XVI32 to look at the binary.
I removed a single space from the end of the file and I re-save the file and it shows up fine. I put it back in and the problem returned. I change the first hex character from 32 to anything less than 30 and it works fine.
So this seems like a very bizarre error with Microsoft Notepad.
精彩评论