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. How to pad a string?

How to pad a string?

Scheduled Pinned Locked Moved C / C++ / MFC
jsontutorialquestion
3 Posts 2 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.
  • S Offline
    S Offline
    simoncoul
    wrote on last edited by
    #1

    Hi, I need to be able to create a CString that is always 15 characters long. So I just want to have say the filename and then pad the rest of the 15 characters with spaces, anyone know of an easy way of doing this? Currently I'm just using strlen and a loop, but I think there probably is a better way. Thanks Simon

    D 1 Reply Last reply
    0
    • S simoncoul

      Hi, I need to be able to create a CString that is always 15 characters long. So I just want to have say the filename and then pad the rest of the 15 characters with spaces, anyone know of an easy way of doing this? Currently I'm just using strlen and a loop, but I think there probably is a better way. Thanks Simon

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      CString s;
      s.Format("%-15s", "Simon");


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      S 1 Reply Last reply
      0
      • D David Crow

        CString s;
        s.Format("%-15s", "Simon");


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        S Offline
        S Offline
        simoncoul
        wrote on last edited by
        #3

        David you are such a great help. Thank you!

        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