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 / C++ / MFC
  4. total number digit in string name.

total number digit in string name.

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
4 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.
  • P Offline
    P Offline
    pnpfriend
    wrote on last edited by
    #1

    Hello all gurus.. If I want to create the string that contains given digit like 3 for 3 digit in the string, how should i done it? To clear what I'm trying to say, here is an example. CString prefix = "pf"; int numDigit = 6; int startNum = 1; CString k; k.Format("%d%d",numDigit,startNum); k = prefix + k; the output that I want is: k = "pf0001" I know I'm doing it wrong.. coz the answer wasn't the one i want it and is there any other way instead of using for or while loop, counting numberDigit.

    B 1 Reply Last reply
    0
    • P pnpfriend

      Hello all gurus.. If I want to create the string that contains given digit like 3 for 3 digit in the string, how should i done it? To clear what I'm trying to say, here is an example. CString prefix = "pf"; int numDigit = 6; int startNum = 1; CString k; k.Format("%d%d",numDigit,startNum); k = prefix + k; the output that I want is: k = "pf0001" I know I'm doing it wrong.. coz the answer wasn't the one i want it and is there any other way instead of using for or while loop, counting numberDigit.

      B Offline
      B Offline
      Bhaskar
      wrote on last edited by
      #2

      Try this. It works. CString prefix = "pf"; int numDigit = 6; int startNum = 1; CString k; k.Format("%0*d",numDigit-prefix.GetLength(),startNum); k = prefix + k; cout << (LPCTSTR) k;

      I 1 Reply Last reply
      0
      • B Bhaskar

        Try this. It works. CString prefix = "pf"; int numDigit = 6; int startNum = 1; CString k; k.Format("%0*d",numDigit-prefix.GetLength(),startNum); k = prefix + k; cout << (LPCTSTR) k;

        I Offline
        I Offline
        Ivan Cachicatari
        wrote on last edited by
        #3

        Saving one line :D

        CString prefix = "pf";
        int numDigit = 6;
        int startNum = 1;

        CString k;
        k.Format("%s%0*d",prefix,numDigit-prefix.GetLength(),startNum);
        cout << (LPCTSTR) k;

        Ivan Cachicatari www.latindevelopers.com

        P 1 Reply Last reply
        0
        • I Ivan Cachicatari

          Saving one line :D

          CString prefix = "pf";
          int numDigit = 6;
          int startNum = 1;

          CString k;
          k.Format("%s%0*d",prefix,numDigit-prefix.GetLength(),startNum);
          cout << (LPCTSTR) k;

          Ivan Cachicatari www.latindevelopers.com

          P Offline
          P Offline
          pnpfriend
          wrote on last edited by
          #4

          Thank you both

          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