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#
  4. C parsing question

C parsing question

Scheduled Pinned Locked Moved C#
c++jsontutorialquestion
5 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.
  • S Offline
    S Offline
    Software2007
    wrote on last edited by
    #1

    I know how to do this in C++, but a bit rusty on C,

    char line[1024]="d(Text1)b(ID1)n(node1)d(Text2)b(ID2)n(node2)d(Text3)b(ID3)n(node3)...
    I would like to parse the line above into item0 = d(Text1)b(ID1)n(node1), item2 - d(Text2)b(ID2)n(node2)... and so forth

    char *py;
    char *px = line;
    while ((py=strstr(px,"d(")) != NULL) {
    // if ((px=strstr(py,")")) == NULL)
    // printf("error1");
    px++;
    }

    return 0;

    Thanks

    P 1 Reply Last reply
    0
    • S Software2007

      I know how to do this in C++, but a bit rusty on C,

      char line[1024]="d(Text1)b(ID1)n(node1)d(Text2)b(ID2)n(node2)d(Text3)b(ID3)n(node3)...
      I would like to parse the line above into item0 = d(Text1)b(ID1)n(node1), item2 - d(Text2)b(ID2)n(node2)... and so forth

      char *py;
      char *px = line;
      while ((py=strstr(px,"d(")) != NULL) {
      // if ((px=strstr(py,")")) == NULL)
      // printf("error1");
      px++;
      }

      return 0;

      Thanks

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Because you posted this in the C# forum I assume you mean you want a solution in C#, so I recommend using a Regular Expression. Something like this might be a good start: d\([^)]*\)b\([^)]*\)n\([^)]*\) If not, there is a Regular Expressions forum.

      S 1 Reply Last reply
      0
      • P PIEBALDconsult

        Because you posted this in the C# forum I assume you mean you want a solution in C#, so I recommend using a Regular Expression. Something like this might be a good start: d\([^)]*\)b\([^)]*\)n\([^)]*\) If not, there is a Regular Expressions forum.

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

        Sorry, I meant to post it on the C/C++ forum, will post it there. Thanks

        N 1 Reply Last reply
        0
        • S Software2007

          Sorry, I meant to post it on the C/C++ forum, will post it there. Thanks

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          There is only a pound of difference between C and C # :-D


          No comment

          D 1 Reply Last reply
          0
          • N Not Active

            There is only a pound of difference between C and C # :-D


            No comment

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

            That's quite a sharp comment, although if you were British you might have made a hash of it.

            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