ILearnable .Net

October 8, 2008

string.Format returns the wrong kind of whitespace

Filed under: Uncategorized — andreakn @ 23:16

ok, this one is weird:

I write a custom util method to format money strings,

it relies on string.Format(“{0:n}”, someValue).

I cover it with unit tests to verify it works, and when I run them

I get this little gem:

It turns out that the whitespace returned from string.Format is character 160, whereas the whitespace you normally get is character 32.

So I change my method to replace all char 160 into char 32, and voila! all the tests pass…

what’s up with that? I didn’t even know there were two chars in .Net that both returned whitespace…

Blog at