Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StreamWriter Problem - 2 Spaces Written as Hex '20 c2 a0' instead of Hex '20 20'

Tags:

c#

I'm writing a bunch of strings to a file using a string writer but I've discovered a problem when I look at the file created in hex, and that is that one of the spaces (x20) is replaced with a non-breaking space instead (xc2 a0) when there are 2 spaces separating words. I don't know if this is a big deal but I would like to know if there is an easy resolution to this?

Here's what I'm seeing:

20 c2 a0 53 57 45 45 50 Dump = "  SWEEP"

But I would like it to always be:

20 20 53 57 45 45 50    Dump = "  SWEEP"

Note that the c2 a0 aren't visible here but the dump looks something like 'A.' when I use the Notepad++ Hex Plugin.

Does anyone have any ideas?

Cheers and Thanks In Advance;

-Daver

like image 840
Daver Avatar asked May 31 '10 22:05

Daver


1 Answers

If your source contains non-breaking spaces you can replace them before writing out the string.

string sourceString = ..some string...
sourceString = sourceString.Replace((char)160, ' '); //replace nobr with space
like image 173
Mikael Svenson Avatar answered Oct 10 '22 12:10

Mikael Svenson