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

Posted by Daver on Stack Overflow See other posts from Stack Overflow or by Daver
Published on 2010-05-31T22:00:37Z Indexed on 2010/05/31 22:03 UTC
Read the original article Hit count: 454

Filed under:

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

© Stack Overflow or respective owner

Related posts about c#