Craig,
In addition to the other comments.
You can use String.PadLeft & String.PadRight to return a new string that is
padded to a certain length.
http://msdn.microsoft.com/library/de...dlefttopic.asp http://msdn.microsoft.com/library/de...righttopic.asp
| string s = new string(' ', 20);
s = "Hi!".PadRight(20, ' ');
- or -
s = "Hi!".PadRight(20);
| Console.WriteLine( "["+ s +"]" );
Alternatively you could use a format string.
| s = "Hi!";
Console.WriteLine("[{0,-20}]", s);
I would use PadRight in a property, if the backing field always needs to be
a certain length, I would use the a format string, if the length is only
important for "presentation".
Hope this helps
Jay
<cr************@hotmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
| Hi,
|
| If I initialize a string like this :
|
| string s = new string(' ', 20);
| s = "Hi!";
| Console.WriteLine( "["+ s +"]" );
|
| It clearly shows that the declaration of the initial length of the
| string serves no purpose for the sake of keeping the size of the
| string.
|
| For a task I'm doing I need a string that keeps its length, filled with
| spaces on left.
| Is there a class already there available ?
|
| Thanks in advance,
|