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. Processing CStdioFile

Processing CStdioFile

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 3 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.
  • S Offline
    S Offline
    Stevieslu
    wrote on last edited by
    #1

    I have to work with a large file with variable rows and columns and I want to make it into 1 large column so I can read all the data using the ReadString command i.e. I need to replace the spaces along each row with newlines(\n)'s. What can I use to do this? Any help would be much appreciated... ----------------

    realJSOPR M 2 Replies Last reply
    0
    • S Stevieslu

      I have to work with a large file with variable rows and columns and I want to make it into 1 large column so I can read all the data using the ReadString command i.e. I need to replace the spaces along each row with newlines(\n)'s. What can I use to do this? Any help would be much appreciated... ----------------

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #2

      Well, I have a couple of solutions: 1) You could replace the spaces as you read the strings from the file 2) You could use CQStringParser, and let it parse each string as it's read into space-delimited fields, and the read the fields one at a time out of the object. Of course, you'd probably want to create an array of CQStringParser objects too. "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

      S 1 Reply Last reply
      0
      • realJSOPR realJSOP

        Well, I have a couple of solutions: 1) You could replace the spaces as you read the strings from the file 2) You could use CQStringParser, and let it parse each string as it's read into space-delimited fields, and the read the fields one at a time out of the object. Of course, you'd probably want to create an array of CQStringParser objects too. "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

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

        What do I use to replace the spaces as I read the strings from the file? I am trying to use strtok at present with limited success. Thanks for your help by the way, -Regards Steve

        realJSOPR 1 Reply Last reply
        0
        • S Stevieslu

          I have to work with a large file with variable rows and columns and I want to make it into 1 large column so I can read all the data using the ReadString command i.e. I need to replace the spaces along each row with newlines(\n)'s. What can I use to do this? Any help would be much appreciated... ----------------

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          Do you just need to make a one-time change to the file? (That's what it sounds like to me.) Install Perl from ActiveState and run this from the command line: perl -pi.bak -e 's/\s+/\n/g' yourfile.txt That replaces any group of 1+ spaces with a newline (and saves a backup in yourfile.txt.bak just in case). --Mike-- http://home.inreach.com/mdunn/ "Not our fault we are intellectually superior to the rest of the office." -- Paul Watson in the Lounge, 12/12/2001 Sonork - 100.10414 AcidHelm

          1 Reply Last reply
          0
          • S Stevieslu

            What do I use to replace the spaces as I read the strings from the file? I am trying to use strtok at present with limited success. Thanks for your help by the way, -Regards Steve

            realJSOPR Offline
            realJSOPR Offline
            realJSOP
            wrote on last edited by
            #5

            I wouldn't use strtok (mostly because I wrote the CQStringParser class). If you're using CStdio, you're using MFC. If you're using MFC, CQStringParser would be abetter choice because it parses the strings for you without you having to do anything but instantiate an object with a string and a delimiter character. Check out that class and see if it doesn't work better than strtok. Besides all that, CString has a Replace() function that can replace all instances of one character with another. "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

            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