Format function... Confused!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Verona

    Format function... Confused!

    I'm a little confused

    I have a string that contains a number eg 11 that I want to format into a 4
    character string with leading zeros ie 0011

    I guess I need to use the "format" function.... ie
    newstring=forma t(oldstring,"?? ??")

    What goes in as the format conversion to get the affect I want?

    Thanks in advance
    Simon

    --
    =============== =============== ==
    Simon Verona
    Dealer Management Service Ltd
    Stewart House
    Centurion Business Park
    Julian Way
    Sheffield
    S9 1GD

    Tel: 0870 080 2300
    Fax: 0870 735 0011


  • Cerebrus

    #2
    Re: Format function... Confused!

    Hi,

    Try Format(oldstrin g, "0000").

    For more information refer to the "User-defined Numeric Formats" topic
    of the Format function.

    Regards,

    Cerebrus.

    Comment

    • Branco Medeiros

      #3
      Re: Format function... Confused!


      Simon Verona wrote:
      <snip>[color=blue]
      > I have a string that contains a number eg 11 that I want to format into a 4
      > character string with leading zeros ie 0011
      >
      > I guess I need to use the "format" function.... ie
      > newstring=forma t(oldstring,"?? ??")[/color]
      <snip>

      Instead of Format, you may use PadLeft method of the String type:

      NewString = OldString.PadLe ft(4, "0"c)

      This will return a string with 4 or less "0" to the left: "1" ->
      "0001"; "12" -> "0012", etc.

      Regards,

      Branco.

      Comment

      • Jim Hughes

        #4
        Re: Format function... Confused!

        PadLeft

        Dim i As Integer = 11
        Trace.WriteLine (i.ToString.Pad Left(4, "0"c))

        "Simon Verona" <nomail@nomail. zzz> wrote in message
        news:%239C0Z5WV GHA.5248@TK2MSF TNGP10.phx.gbl. ..[color=blue]
        > I'm a little confused
        >
        > I have a string that contains a number eg 11 that I want to format into a
        > 4 character string with leading zeros ie 0011
        >
        > I guess I need to use the "format" function.... ie
        > newstring=forma t(oldstring,"?? ??")
        >
        > What goes in as the format conversion to get the affect I want?
        >
        > Thanks in advance
        > Simon
        >
        > --
        > =============== =============== ==
        > Simon Verona
        > Dealer Management Service Ltd
        > Stewart House
        > Centurion Business Park
        > Julian Way
        > Sheffield
        > S9 1GD
        >
        > Tel: 0870 080 2300
        > Fax: 0870 735 0011
        >
        >[/color]


        Comment

        • Kell Ethridge

          #5
          Re: Format function... Confused!

          Oh, let me try, too :)

          Dim i As Integer = 11
          Dim s As String = i.ToString("d4" )


          Kelly



          "Simon Verona" <nomail@nomail. zzz> wrote in message
          news:%239C0Z5WV GHA.5248@TK2MSF TNGP10.phx.gbl. ..[color=blue]
          > I'm a little confused
          >
          > I have a string that contains a number eg 11 that I want to format into a
          > 4 character string with leading zeros ie 0011
          >
          > I guess I need to use the "format" function.... ie
          > newstring=forma t(oldstring,"?? ??")
          >
          > What goes in as the format conversion to get the affect I want?
          >
          > Thanks in advance
          > Simon
          >
          > --
          > =============== =============== ==
          > Simon Verona
          > Dealer Management Service Ltd
          > Stewart House
          > Centurion Business Park
          > Julian Way
          > Sheffield
          > S9 1GD
          >
          > Tel: 0870 080 2300
          > Fax: 0870 735 0011
          >
          >[/color]


          Comment

          Working...