Results 1 to 5 of 5

Thread: [RESOLVED] help with formatting using string.format

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Location
    Vermont
    Posts
    12

    Resolved [RESOLVED] help with formatting using string.format

    I wish to have Result(3) zero padded on the left so that it's always 2 characters wide. I don't know how to accomplish this. for instance, if Result(2) is 1 and Result(3) is 5, I want it displayed as '1.05'. if Result(2) is 1 and Result(3) is 12, I want it displayed as '1.12'. How can this be accomplished?

    Code:
    lblVersion.Text = String.Format("{0}.{1}", Result(2), Result(3))

    Thanks.
    Peter

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: help with formatting using string.format

    Are you looking for this one....

    Code:
    lblVersion.Text = String.Format("{0}.{1:##}", Result(2), Result(3))
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Location
    Vermont
    Posts
    12

    Re: help with formatting using string.format

    That didn't seem to work.

    Thanks for the suggestion.

    Pete

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: help with formatting using string.format

    The # symbol is for optional digits. 0 is for mandatory digits.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Location
    Vermont
    Posts
    12

    Re: help with formatting using string.format

    Oops! I didn't realize I needed to replace the '##' with '00'. It works now. Thank you for your help.

    Peter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width