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. how to get part of the string after blank

how to get part of the string after blank

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
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.
  • A Offline
    A Offline
    amit code
    wrote on last edited by
    #1

    hi.. i have a string of format "name tom". how can i get out tom out of it. regards

    amit

    CPalliniC C H 3 Replies Last reply
    0
    • A amit code

      hi.. i have a string of format "name tom". how can i get out tom out of it. regards

      amit

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

      You may search for the ' ' token, for instance (plain C)

      char string[] = "name tom";
      char * p;
      p = strtok(string, " "); // p points to "name"
      p = strtok(NULL, " "); // p points to "tom"

      :)

      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

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • A amit code

        hi.. i have a string of format "name tom". how can i get out tom out of it. regards

        amit

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        What is the type of your string ? std::string, CString (MFC) or a plain char* (or TCHAR* or wchar*) ? For the last one, take a look at strtok[^] (and choose the correct version depending on your UNICODE settings).

        Cédric Moonen Software developer
        Charting control [v1.4]

        A 1 Reply Last reply
        0
        • C Cedric Moonen

          What is the type of your string ? std::string, CString (MFC) or a plain char* (or TCHAR* or wchar*) ? For the last one, take a look at strtok[^] (and choose the correct version depending on your UNICODE settings).

          Cédric Moonen Software developer
          Charting control [v1.4]

          A Offline
          A Offline
          amit code
          wrote on last edited by
          #4

          Thanks for reply.. it works Regards

          amit

          1 Reply Last reply
          0
          • A amit code

            hi.. i have a string of format "name tom". how can i get out tom out of it. regards

            amit

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            If you are using of MFC you can use of CString::Mid or CString::Find and then CString::Right.

            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