Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to customize strings with Format method?

How to customize strings with Format method?

Scheduled Pinned Locked Moved C#
tutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Diego F
    wrote on last edited by
    #1

    Hello, I'm not sure about how to customize formats in strings. I.e, I want a string that is an integer number, but with some zeros at the beginning to have a certain length. So, if I have an integer value: i = 1, I want to convert it to string so it gets: "000001", with length 6. I'm trying with i.ToString(), trying to guess which format to put to achieve that. Do you know the solution?

    Regards, Diego F.

    D P 2 Replies Last reply
    0
    • D Diego F

      Hello, I'm not sure about how to customize formats in strings. I.e, I want a string that is an integer number, but with some zeros at the beginning to have a certain length. So, if I have an integer value: i = 1, I want to convert it to string so it gets: "000001", with length 6. I'm trying with i.ToString(), trying to guess which format to put to achieve that. Do you know the solution?

      Regards, Diego F.

      D Offline
      D Offline
      Diego F
      wrote on last edited by
      #2

      I found other way to get that without the format method. I used the Padleft method and I get the same :)

      Regards, Diego F.

      1 Reply Last reply
      0
      • D Diego F

        Hello, I'm not sure about how to customize formats in strings. I.e, I want a string that is an integer number, but with some zeros at the beginning to have a certain length. So, if I have an integer value: i = 1, I want to convert it to string so it gets: "000001", with length 6. I'm trying with i.ToString(), trying to guess which format to put to achieve that. Do you know the solution?

        Regards, Diego F.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        ToString ( "000000" )

        L D 2 Replies Last reply
        0
        • P PIEBALDconsult

          ToString ( "000000" )

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          or ToString("D6"); analogous to ToString("X8"); for hex

          Luc Pattyn [Forum Guidelines] [My Articles]


          this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


          1 Reply Last reply
          0
          • P PIEBALDconsult

            ToString ( "000000" )

            D Offline
            D Offline
            Diego F
            wrote on last edited by
            #5

            I was sure it was simple, but is soooo simple that I'm feeling embarrased :doh:

            Regards, Diego F.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups