String.Format: What is "{0}"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?cmFuZHkxMjAw?=

    String.Format: What is "{0}"

    I have the following:

    String.Format(" {0}", myNumber);

    What is {0} called? The reason I ask is that I want to look up how present
    myNumber as 2 digits in the string. For example, if myNumber is 3, the string
    should be 03. If I just use something like {0:2}, I get a space preceeding
    the 3.

    Thanks,
    Randy
  • Bob Grommes

    #2
    Re: String.Format: What is "{0}&qu ot;

    Search for "Standard Numeric Format Strings" and "Custom Numeric Format
    String" in help.

    Going from memory I believe what you want is {0:00} or {0:N02}. The
    latter handles negative numbers and thousand separators, the former just
    left-justifies with zeros.

    --Bob

    randy1200 wrote:
    I have the following:
    >
    String.Format(" {0}", myNumber);
    >
    What is {0} called? The reason I ask is that I want to look up how present
    myNumber as 2 digits in the string. For example, if myNumber is 3, the string
    should be 03. If I just use something like {0:2}, I get a space preceeding
    the 3.
    >
    Thanks,
    Randy

    Comment

    • pigeonrandle

      #3
      Re: String.Format: What is "{0}&qu ot;

      HI,
      Have a look at
      Converts the value of objects to strings based on the formats specified and inserts them into another string. If you are new to the String.Format method, see Get started with the String.Format method for a quick overview.

      HTH,
      James


      On 26 Apr, 00:22, randy1200 <randy1...@disc ussions.microso ft.com>
      wrote:
      I have the following:
      >
      String.Format(" {0}", myNumber);
      >
      What is {0} called? The reason I ask is that I want to look up how present
      myNumber as 2 digits in the string. For example, if myNumber is 3, the string
      should be 03. If I just use something like {0:2}, I get a space preceeding
      the 3.
      >
      Thanks,
      Randy

      Comment

      Working...