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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Parsing in C

Parsing in C

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsonquestion
9 Posts 5 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
    Software2007
    wrote on last edited by
    #1

    In C not C++,
    I have LPTSTR str = "texttext2header";

    I would like to delete all tags NOT NAMED xyz How do iterate through without deleting the 'xyz' tag ?

    C D 2 Replies Last reply
    0
    • S Software2007

      In C not C++,
      I have LPTSTR str = "texttext2header";

      I would like to delete all tags NOT NAMED xyz How do iterate through without deleting the 'xyz' tag ?

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      Suggestion. Write a function that searches for the start of the tag and returns the index of the opening <. Write another function that searches for the end of the tag and returns the index of the closing >. Then write a function that 'moves' everything from after the end index to the opening index. :)

      Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

      S 1 Reply Last reply
      0
      • C Chris Meech

        Suggestion. Write a function that searches for the start of the tag and returns the index of the opening <. Write another function that searches for the end of the tag and returns the index of the closing >. Then write a function that 'moves' everything from after the end index to the opening index. :)

        Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

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

        Sorry, don't quite follow.

        C L 2 Replies Last reply
        0
        • S Software2007

          Sorry, don't quite follow.

          C Offline
          C Offline
          Chris Meech
          wrote on last edited by
          #4

          How about an ASCII picture.

                                Start        End
                                Index       Index
                                  |           |
          

          LPTSTR str = "texttext2header";
          | |____|
          | Stuff to move-+
          | |
          +--<--< goes here -<--<-+

          The first function will return the start index. The second function will return the end index. The third function will move all characters after the end index to the end of the string and place them in start index resulting in

          LPTSTR str = "texttext2";

          Hope that is clearer. :)

          Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

          CPalliniC 1 Reply Last reply
          0
          • S Software2007

            In C not C++,
            I have LPTSTR str = "texttext2header";

            I would like to delete all tags NOT NAMED xyz How do iterate through without deleting the 'xyz' tag ?

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

            Iterate over the string, copying characters from source to destination. If you see a tag not named xyz, stop copying until the matching tag is encountered.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

            S 1 Reply Last reply
            0
            • D David Crow

              Iterate over the string, copying characters from source to destination. If you see a tag not named xyz, stop copying until the matching tag is encountered.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

              S Offline
              S Offline
              Software2007
              wrote on last edited by
              #6

              This is what I was looking for, I just couldn't get it to work. Could you show a pseudo snippet of code in C? Thanks

              D 1 Reply Last reply
              0
              • S Software2007

                This is what I was looking for, I just couldn't get it to work. Could you show a pseudo snippet of code in C? Thanks

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

                const char *pszSource = "texttext2header";
                char szDest[128] = { '\0' };
                int x = 0;

                while (pszSource && *pszSource != '\0')
                {
                // you'll need to put some conditions here to detect tags

                = *pszSource;

                x++;
                pszSource++;
                }

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

                1 Reply Last reply
                0
                • C Chris Meech

                  How about an ASCII picture.

                                        Start        End
                                        Index       Index
                                          |           |
                  

                  LPTSTR str = "texttext2header";
                  | |____|
                  | Stuff to move-+
                  | |
                  +--<--< goes here -<--<-+

                  The first function will return the start index. The second function will return the end index. The third function will move all characters after the end index to the end of the string and place them in start index resulting in

                  LPTSTR str = "texttext2";

                  Hope that is clearer. :)

                  Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

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

                  Beautiful picture. :)

                  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.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  In testa che avete, signor di Ceprano?

                  1 Reply Last reply
                  0
                  • S Software2007

                    Sorry, don't quite follow.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Use strchr(). Look for left angle bracket. Read the next char. If it isnt an 'x' then delete everything up to and including the next right angle bracket with a matching tag.

                    ============================== Nothing to say.

                    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