Home All Groups Group Topic Archive Search About

Setting StringBuilder.Length not behaving per documentation

Author
21 Aug 2006 3:06 PM
soccerdad
Perhaps this has been discussed elsewhere - if so, I couldn't find it.

The StringBuilder.Length property is explicitly documented as padding the
length with spaces if .Length is set to a value greater than the current
length. I'm hoping to get this behavior. However, when I set .Length to
something greater than the current length, the padding is done with null
characters ('\0'), not spaces. Is this the actual intended behavior (and the
docs are wrong) or a bug (and the docs are right)?

Any help in this would be appreciated. Thanks,

Donnie

Author
21 Aug 2006 3:25 PM
Vadym Stetsyak
Hello, soccerdad!

s> The StringBuilder.Length property is explicitly documented as padding
s> the length with spaces if .Length is set to a value greater than the
s> current length. I'm hoping to get this behavior. However, when I set
s> .Length to something greater than the current length, the padding is
s> done with null characters ('\0'), not spaces. Is this the actual
s> intended behavior (and the docs are wrong)
s> or a bug (and the docs are right)?

IMO the docs are not right, or they're not reflecting what is
really happening. 

I think that it is correct to do padding with \0. Imagine
what whould happen if you will increase string length,
and then call StringBuilder.ToString()?

Space is a character. Some other developer after calling
StringBuilder.ToString() will cry: "What happened? I didn't insert those spaces".

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

AddThis Social Bookmark Button