[Mono-list] Interpretation of the spec for StringBuilder..

Marcin Szczepanski marcins@zipworld.com.au
Wed, 11 Jul 2001 14:22:21 +1000


Already found something that's a bit weird and I've barely started!

This is the description for the StringBuilder.Length property:
If the specified length is less than the current length, the
StringBuilder is truncated to the specified length. If the specified
length is greater than the current length, the Capacity of the current
instance is set to the specified length, padding its string value with
spaces on the left.

The first bit of this is fine, however the second seems a bit confusing.
It's saying to put the padding on the left?! 

So if I have a string "foo" and I do Length = 6 then the string will be:
"   foo" 
and not 
"foo   ", which would make more sense.  

What does everyone else think??

Actually, I'll try the MS implementation and see what it does...  Okay,
the MS implementation puts the padding on the right, ie. This code:
[...]
                StringBuilder sb = new StringBuilder( "foo" );
                Console.WriteLine( ">{0}<", sb.ToString() );
                sb.Length = 6;
                Console.WriteLine( ">{0}<", sb.ToString() );
[...]

Gives this result:
>foo<
>foo   <

Is this a case of LAMESPEC or am I just misreading the spec??   Either
that or they just wrote left where they meant right :)

Thanks for your time :)