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 remove the "0" from the starting i.e. from the left of the CString

How to remove the "0" from the starting i.e. from the left of the CString

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
4 Posts 4 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
    deadlyabbas
    wrote on last edited by
    #1

    Hi, I am having the follwoing CString "0000122334" and I need to remove the starting zeros from the string. Kindly help. Thanks in Advance.

    P C _ 3 Replies Last reply
    0
    • D deadlyabbas

      Hi, I am having the follwoing CString "0000122334" and I need to remove the starting zeros from the string. Kindly help. Thanks in Advance.

      P Offline
      P Offline
      Prasann Mayekar
      wrote on last edited by
      #2

      TrimLeft("0"); call this CString member function.

      1 Reply Last reply
      0
      • D deadlyabbas

        Hi, I am having the follwoing CString "0000122334" and I need to remove the starting zeros from the string. Kindly help. Thanks in Advance.

        C Offline
        C Offline
        Code o mat
        wrote on last edited by
        #3

        Just a sidenote to what Prasann Mayekar said: if your string contains only zeroes, "0000", trimming it will result in an empty string, also, if you can have fractions, like "0.45", then trimming will result in ".45".

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > //TODO: Implement signature here<

        1 Reply Last reply
        0
        • D deadlyabbas

          Hi, I am having the follwoing CString "0000122334" and I need to remove the starting zeros from the string. Kindly help. Thanks in Advance.

          _ Offline
          _ Offline
          _AnsHUMAN_
          wrote on last edited by
          #4

          There can be various ways of doing this: 1. Use the Replace method from the CString class 2. Iterate through the characters in the string, until you get a non zero element. Store the index here and use the TrimXYZ function from the CString class.

          You talk about Being HUMAN. I have it in my name AnsHUMAN

          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