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 parse non string data

how to parse non string data

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
8 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.
  • A Offline
    A Offline
    Arris74
    wrote on last edited by
    #1

    Hello, Hope it is not a stupid question but suppose I have an int i = 20031225 and I would like to parse it to get the 4 first figures (2003) and the last 2 figures (25), like the functions CStringT::Left and CStringT::Right. is it possible to do it without too much coding and without converting into string? Thnks.

    D 1 Reply Last reply
    0
    • A Arris74

      Hello, Hope it is not a stupid question but suppose I have an int i = 20031225 and I would like to parse it to get the 4 first figures (2003) and the last 2 figures (25), like the functions CStringT::Left and CStringT::Right. is it possible to do it without too much coding and without converting into string? Thnks.

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

      Arris7 wrote:

      I would like to parse it to get the 4 first figures (2003)...

      Divide by 10000. Why are you against using an intermediary string?


      "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

      A 1 Reply Last reply
      0
      • D David Crow

        Arris7 wrote:

        I would like to parse it to get the 4 first figures (2003)...

        Divide by 10000. Why are you against using an intermediary string?


        "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

        A Offline
        A Offline
        Arris74
        wrote on last edited by
        #3

        Dividing by 10000 is a very good idea. And to get the latest 2 figures by doing i%100 works fine also. Actually I use a huge amount of data and it takes too much time to process. I also would like to get any numbers from the figure. for example I would like to extract 01 from 20030112. Is it doable?

        C 1 Reply Last reply
        0
        • A Arris74

          Dividing by 10000 is a very good idea. And to get the latest 2 figures by doing i%100 works fine also. Actually I use a huge amount of data and it takes too much time to process. I also would like to get any numbers from the figure. for example I would like to extract 01 from 20030112. Is it doable?

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          Of course, you can do:

          extraction = (i / 100) % 100;

          but, as already stated by DavidCrow, this is better done using strings. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          D A 2 Replies Last reply
          0
          • C CPallini

            Of course, you can do:

            extraction = (i / 100) % 100;

            but, as already stated by DavidCrow, this is better done using strings. :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

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

            CPallini wrote:

            but, as already stated by DavidCrow, this is better done using strings.

            I never said one way was any better than the other. I was simply asking why he was adamantly against the string solution. It would take quite a bit of empirical testing to find which of the two methods was the "better" one. One might be faster, but the other could be more intuitive.


            "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

            C 1 Reply Last reply
            0
            • C CPallini

              Of course, you can do:

              extraction = (i / 100) % 100;

              but, as already stated by DavidCrow, this is better done using strings. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

              A Offline
              A Offline
              Arris74
              wrote on last edited by
              #6

              thanks for the solution. but why using string is better? In my case I use a huge volume of data of int type and my data is fixed length. data extracted with the solutions you provided me will be used for calculations. So converting to string + parsing data + reconverting again to int will probably be expensive in term of execution speed.

              C 1 Reply Last reply
              0
              • D David Crow

                CPallini wrote:

                but, as already stated by DavidCrow, this is better done using strings.

                I never said one way was any better than the other. I was simply asking why he was adamantly against the string solution. It would take quite a bit of empirical testing to find which of the two methods was the "better" one. One might be faster, but the other could be more intuitive.


                "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

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #7

                Yes, I oversimplified. Using strings makes code more clear. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                1 Reply Last reply
                0
                • A Arris74

                  thanks for the solution. but why using string is better? In my case I use a huge volume of data of int type and my data is fixed length. data extracted with the solutions you provided me will be used for calculations. So converting to string + parsing data + reconverting again to int will probably be expensive in term of execution speed.

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #8

                  Arris7 wrote:

                  So converting to string + parsing data + reconverting again to int will probably be expensive in term of execution speed

                  I don't know. Maybe it depends on what you are exactly doing... :-D

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                  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