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. string operation

string operation

Scheduled Pinned Locked Moved C / C++ / MFC
help
6 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.
  • R Offline
    R Offline
    robin700
    wrote on last edited by
    #1

    i have a string such that hello hi good i want to extract the values line by line....please help

    L 1 Reply Last reply
    0
    • R robin700

      i have a string such that hello hi good i want to extract the values line by line....please help

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

      What sort of string, and what do you mean by extract the values line by line? You could use one of the strtok[^] variants for a simple character array, or one of these functions[^] for a string.

      Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

      R 1 Reply Last reply
      0
      • L Lost User

        What sort of string, and what do you mean by extract the values line by line? You could use one of the strtok[^] variants for a simple character array, or one of these functions[^] for a string.

        Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

        R Offline
        R Offline
        robin700
        wrote on last edited by
        #3

        i have a character array such thatb char buffer[100]; the values are stored like cklvcmsdl dclcm dcpcc i have to extract these values line by line and compare them with the input to find matching usernames buffer contains the usernames

        L C 2 Replies Last reply
        0
        • R robin700

          i have a character array such thatb char buffer[100]; the values are stored like cklvcmsdl dclcm dcpcc i have to extract these values line by line and compare them with the input to find matching usernames buffer contains the usernames

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

          Well it looks like you need to use the first option I suggested.

          Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

          1 Reply Last reply
          0
          • R robin700

            i have a character array such thatb char buffer[100]; the values are stored like cklvcmsdl dclcm dcpcc i have to extract these values line by line and compare them with the input to find matching usernames buffer contains the usernames

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

            That means the user names are separated by the newline character, you may use strtok as Richard already suggested or hand-craft a simple loop to collect all the names.

            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]

            S 1 Reply Last reply
            0
            • C CPallini

              That means the user names are separated by the newline character, you may use strtok as Richard already suggested or hand-craft a simple loop to collect all the names.

              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]

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

              As CPallinial suggested, here is simple loop to collect all the names.

              #include <iostream>
              #include <algorithm>
              #include <vector>
              #include <string>

              using namespace std;

              char one_line_string[] = "hello hi how are you nice weather we are having ok then bye";
              char seps[] = " ,\t\n";
              char *token;

              int main()
              {
              vector<string> vec_String_Lines;
              token = strtok( one_line_string, seps );

              cout << "Extracting and storing data in a vector..\n\n\n";

              while( token != NULL )
              {
              vec_String_Lines.push_back(token);
              token = strtok( NULL, seps );
              }
              cout << "Displaying end result in vector line storage..\n\n";

              for ( int i = 0; i < vec\_String\_Lines.size(); ++i)
              cout << vec\_String\_Lines\[i\] << "\\n";
              cout << "\\n\\n\\n";
              

              return 0;
              }

              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