Spacer characters in format strings

Discussion in 'ASP .Net' started by Nathan Sokalski, May 20, 2008.

  1. 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.
     
    Nathan Sokalski, May 20, 2008
    #1
    1. Advertisements

  2. Use String.PadLeft Method
    http://msdn.microsoft.com/en-us/library/system.string.padleft.aspx
     
    Alexey Smirnov, May 20, 2008
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.