[英]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.我试图制作一个固定宽度的文件,但我发现当我使用空格字符时,我的 txt 文件中有一个奇怪的标志。 If I change the "50" number to something like "15" or "1000", it works fine.
如果我将“50”数字更改为“15”或“1000”之类的数字,它可以正常工作。
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.
我拿了你程序的 output,它在 Microsoft 记事本中确实显示得很奇怪,然后在其他几个编辑器中打开它。 It appears fine in all of them.
在所有这些中看起来都很好。 Convinced it was some encoding error, I then cracked open XVI32 to look at the binary.
确信这是一些编码错误,然后我打开 XVI32 来查看二进制文件。
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.
我将第一个十六进制字符从 32 更改为小于 30 的任何字符,它工作正常。
So this seems like a very bizarre error with Microsoft Notepad.所以这似乎是微软记事本的一个非常奇怪的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.