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. Parsing a string that contains only one seperator

Parsing a string that contains only one seperator

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsontutorialquestion
7 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.
  • K Offline
    K Offline
    Kuniva
    wrote on last edited by
    #1

    I have a CString. It contains multiple #'s that break it up. Now i want to get each piece of text seperately between the #'s. For example: Jake#Caroline#Mark#Anthony#Sid# The string ends with # but doesn't start with # (although you can presume otherwise because it can be changed). Hows the easy way to do this? (preferably the MFC CString way ;) ) Thanks P.S.: i'll stop hasssling u ppl now lolz, i'm working on a program thats why i was asking so many questions hehe. Kuniva

    C D RaviBeeR 3 Replies Last reply
    0
    • K Kuniva

      I have a CString. It contains multiple #'s that break it up. Now i want to get each piece of text seperately between the #'s. For example: Jake#Caroline#Mark#Anthony#Sid# The string ends with # but doesn't start with # (although you can presume otherwise because it can be changed). Hows the easy way to do this? (preferably the MFC CString way ;) ) Thanks P.S.: i'll stop hasssling u ppl now lolz, i'm working on a program thats why i was asking so many questions hehe. Kuniva

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      The C way would be with strtok, but otherwise, you'd use CString::Find, which allows you to find the first instance of a substring starting from a specified position, and CString::Mid which allows you to pull a substring out of the middle. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

      1 Reply Last reply
      0
      • K Kuniva

        I have a CString. It contains multiple #'s that break it up. Now i want to get each piece of text seperately between the #'s. For example: Jake#Caroline#Mark#Anthony#Sid# The string ends with # but doesn't start with # (although you can presume otherwise because it can be changed). Hows the easy way to do this? (preferably the MFC CString way ;) ) Thanks P.S.: i'll stop hasssling u ppl now lolz, i'm working on a program thats why i was asking so many questions hehe. Kuniva

        D Offline
        D Offline
        David Scambler
        wrote on last edited by
        #3

        try this: :) CString text = "Jake#Caroline#Mark#Anthony#Sid#"; CString name; int index=0; while (AfxExtractSubString(name, text, index++, '#') { if (name != "") { // do something } }

        1 Reply Last reply
        0
        • K Kuniva

          I have a CString. It contains multiple #'s that break it up. Now i want to get each piece of text seperately between the #'s. For example: Jake#Caroline#Mark#Anthony#Sid# The string ends with # but doesn't start with # (although you can presume otherwise because it can be changed). Hows the easy way to do this? (preferably the MFC CString way ;) ) Thanks P.S.: i'll stop hasssling u ppl now lolz, i'm working on a program thats why i was asking so many questions hehe. Kuniva

          RaviBeeR Offline
          RaviBeeR Offline
          RaviBee
          wrote on last edited by
          #4

          One way to do is to copy the CString to a char buffer and strtok() your way through the buffer. (Btw, if you're using the CP forums to get canned answers to your schoolwork, you're only hurting yourself.) /ravi "There is always one more bug..." http://www.ravib.com raviv@ravib.com

          K S 2 Replies Last reply
          0
          • RaviBeeR RaviBee

            One way to do is to copy the CString to a char buffer and strtok() your way through the buffer. (Btw, if you're using the CP forums to get canned answers to your schoolwork, you're only hurting yourself.) /ravi "There is always one more bug..." http://www.ravib.com raviv@ravib.com

            K Offline
            K Offline
            Kuniva
            wrote on last edited by
            #5

            lolz dont worry, its not for school, i'm only 16 we dont get any computer studies in my school, lolz we dont even have computers at my school haha ;) Kuniva

            1 Reply Last reply
            0
            • RaviBeeR RaviBee

              One way to do is to copy the CString to a char buffer and strtok() your way through the buffer. (Btw, if you're using the CP forums to get canned answers to your schoolwork, you're only hurting yourself.) /ravi "There is always one more bug..." http://www.ravib.com raviv@ravib.com

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

              Can you tell me how I copy a string to a char buffer? Sorry if this question is a bit stupid...

              RaviBeeR 1 Reply Last reply
              0
              • S Stevieslu

                Can you tell me how I copy a string to a char buffer? Sorry if this question is a bit stupid...

                RaviBeeR Offline
                RaviBeeR Offline
                RaviBee
                wrote on last edited by
                #7

                Stevieslu wrote: Sorry if this question is a bit stupid... The only stupid question is the one not asked! Here's how:

                char szBuffer [LARGE_ENOUGH_TO_HOLD_STRING];
                CString strMyString = "Whatever";

                szBuffer [0] = '\0';
                if (strMyString.GetLength() < LARGE_ENOUGH_TO_HOLD_STRING) {
                strcpy (szBuffer, strMyString.GetBuffer (0));
                strMyString.ReleaseBuffer();
                }

                /ravi "There is always one more bug..." ravib@ravib.com http://www.ravib.com

                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