Spacer characters in format strings

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

I am trying to make a format string for use in methods such as
String.Format. I want the formatted string to be a fixed length with any
empty spaces to be filled with a specified character. For example, I would
want the following statement:

String.Format("{0,5}","abc")

To return:

00abc

However, when this type of format string is used the empty spaces are filled
with spaces. I am aware that this is what is expected, but is there a way to
specify a character to use for filling the empty spaces? Any help would be
appreciated. Thanks.
 
I am trying to make a format string for use in methods such as
String.Format. I want the formatted string to be a fixed length with any
empty spaces to be filled with a specified character. For example, I would
want the following statement:

String.Format("{0,5}","abc")

To return:

00abc

However, when this type of format string is used the empty spaces are filled
with spaces. I am aware that this is what is expected, but is there a way to
specify a character to use for filling the empty spaces? Any help would be
appreciated. Thanks.

Use String.PadLeft Method
http://msdn.microsoft.com/en-us/library/system.string.padleft.aspx
 
Back
Top