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 tokenize the string

How to tokenize the string

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
5 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.
  • R Offline
    R Offline
    Rassul Yunussov
    wrote on last edited by
    #1

    I got string like this :"Rassul##Rasul#Yunussov"; And i want to tokenize it to strings : "Rassul" and "Rassul#Yunussov". I know the function strtok - but it doesnt distinguish "##" from "#".

    T A B D 4 Replies Last reply
    0
    • R Rassul Yunussov

      I got string like this :"Rassul##Rasul#Yunussov"; And i want to tokenize it to strings : "Rassul" and "Rassul#Yunussov". I know the function strtok - but it doesnt distinguish "##" from "#".

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      you have to get the # character from the string, and test its following character. i'm about to post an article about something like that (parsing streams)... wait a bit ;) (posted) here is a like on parsing code : Visual Calc - A new dimension for the desktop calculator[^]

      char ch = str[NextChar++]; // Be careful to test if the index is not out of bounds...
      switch (ch) {
      case '#':
      {
      char nch = str[NextChar++];
      if (nch == '#') {
      // Do some action when ## is found on the stream...
      }
      else {
      // Only one # was found...
      NextChar--;
      }
      break;
      }
      default:
      // Fisrt character is not #...
      }


      TOXCCT >>> GEII power

      1 Reply Last reply
      0
      • R Rassul Yunussov

        I got string like this :"Rassul##Rasul#Yunussov"; And i want to tokenize it to strings : "Rassul" and "Rassul#Yunussov". I know the function strtok - but it doesnt distinguish "##" from "#".

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

        Perhaps its wiser to choose a different form of formatting your strings. Why use '##' and '#', they already cause problems trying to distinguish them during parsing. How about using '$' and '%' or something like that. '##' and '#' clearly mean different things to you, so why use such similar signs? Er zit een korstje op mijn aars.

        1 Reply Last reply
        0
        • R Rassul Yunussov

          I got string like this :"Rassul##Rasul#Yunussov"; And i want to tokenize it to strings : "Rassul" and "Rassul#Yunussov". I know the function strtok - but it doesnt distinguish "##" from "#".

          B Offline
          B Offline
          BlackDice
          wrote on last edited by
          #4

          If you're using MFC, use CString::Find() to find "##". [insert witty comment here] bdiamond :zzz:

          1 Reply Last reply
          0
          • R Rassul Yunussov

            I got string like this :"Rassul##Rasul#Yunussov"; And i want to tokenize it to strings : "Rassul" and "Rassul#Yunussov". I know the function strtok - but it doesnt distinguish "##" from "#".

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

            How about:

            char *str = "Rassul##Rasul#Yunussov";
            char *pos = strstr(str, "##");
            char left[16], right[16];
            strncpy(left, str, pos - str);
            strcpy(right, pos + 2);


            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

            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