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. Is there a function in C++ that will split a char array delimited by a specific character?

Is there a function in C++ that will split a char array delimited by a specific character?

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structurestutorialquestion
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
    Redeemer dk
    wrote on last edited by
    #1

    If i for example have this string: "192,168,135,97,51,156" is it possible to split that into 6 integers containing the values delimited by the comma? thanks all :)

    M C J 3 Replies Last reply
    0
    • R Redeemer dk

      If i for example have this string: "192,168,135,97,51,156" is it possible to split that into 6 integers containing the values delimited by the comma? thanks all :)

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      strtok should do the thing ... also, could do it by hand with CString ( and/or std::string ) Max.

      D 1 Reply Last reply
      0
      • R Redeemer dk

        If i for example have this string: "192,168,135,97,51,156" is it possible to split that into 6 integers containing the values delimited by the comma? thanks all :)

        C Offline
        C Offline
        Carlos Antollini
        wrote on last edited by
        #3

        Yes strtok Cheers Carlos Antollini. Pi Five[^]Creator Sonork ID 100.10529 cantollini

        1 Reply Last reply
        0
        • M Maximilien

          strtok should do the thing ... also, could do it by hand with CString ( and/or std::string ) Max.

          D Offline
          D Offline
          David Salter
          wrote on last edited by
          #4

          strtok is the one, but be careful if you have "blank" tokens e.g. "1,2,3,,5". strtok will say there are 4 values here rather than 5 (4 numbers and one blank token). Dave.

          1 Reply Last reply
          0
          • R Redeemer dk

            If i for example have this string: "192,168,135,97,51,156" is it possible to split that into 6 integers containing the values delimited by the comma? thanks all :)

            J Offline
            J Offline
            Joe Woodbury
            wrote on last edited by
            #5

            Be aware that strtok is destructive to the original string

            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