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. String formatting

String formatting

Scheduled Pinned Locked Moved C#
csharpc++question
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.
  • L Offline
    L Offline
    Le centriste
    wrote on last edited by
    #1

    In C++, if you write the following:

    printf("Number: 0x%04X", 1);

    The output will be:

    Number: 0x0001

    As one can see, the number is prepended with a zeros. How do you achieve the same with C#?

    L 1 Reply Last reply
    0
    • L Le centriste

      In C++, if you write the following:

      printf("Number: 0x%04X", 1);

      The output will be:

      Number: 0x0001

      As one can see, the number is prepended with a zeros. How do you achieve the same with C#?

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Have a look at the NumberFormatInfo class. typically it it would be: Console.WriteLine("Number: 0x{0}", 1.ToString("X4")); output Number: 0x0001 WebBoxes - Yet another collapsable control, but it relies on a "graphics server" for dynamic pretty rounded corners, cool arrows and unlimited font support.

      L J 2 Replies Last reply
      0
      • L leppie

        Have a look at the NumberFormatInfo class. typically it it would be: Console.WriteLine("Number: 0x{0}", 1.ToString("X4")); output Number: 0x0001 WebBoxes - Yet another collapsable control, but it relies on a "graphics server" for dynamic pretty rounded corners, cool arrows and unlimited font support.

        L Offline
        L Offline
        Le centriste
        wrote on last edited by
        #3

        tx it worked

        1 Reply Last reply
        0
        • L leppie

          Have a look at the NumberFormatInfo class. typically it it would be: Console.WriteLine("Number: 0x{0}", 1.ToString("X4")); output Number: 0x0001 WebBoxes - Yet another collapsable control, but it relies on a "graphics server" for dynamic pretty rounded corners, cool arrows and unlimited font support.

          J Offline
          J Offline
          John Burton
          wrote on last edited by
          #4

          Or in one step :- inx x = 100; System.Console.WriteLine("Number is 0x{0:X4}", x);

          L 1 Reply Last reply
          0
          • J John Burton

            Or in one step :- inx x = 100; System.Console.WriteLine("Number is 0x{0:X4}", x);

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            John Burton wrote: System.Console.WriteLine("Number is 0x{0:X4}", x); Yeah I always forget about that...:omg: WebBoxes - Yet another collapsable control, but it relies on a "graphics server" for dynamic pretty rounded corners, cool arrows and unlimited font support.

            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