Spacer characters in format strings

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.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top