Thread: Delete a string

  1. #1
    Unregistered
    Guest

    Question Delete a string

    Does anyone know of a quick way to delete a line in a file?

  2. #2
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Use notepad if you have Microsoft, or else Kate if you have Linux on KDE.

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    always a comedian.

    My understanding is you will have to move everything up. Perhaps load it all into memory, reopen the file truncated, write it back out without the missing line. If it's a big file you could always copy it to a temp file and do it in chunks.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    Registered User Aran's Avatar
    Join Date
    Aug 2001
    Posts
    1,301
    pseudo-code:

    Code:
    while we aren't at the end of the file
    {
     if the line we are reading is the line we want to delete
     { continue }
     else
     { print the line to the new file }
    }
    delete the old file

  5. #5
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    You forgot:
    Rename new file to name of old file. I'm assuming that's what he wants.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  6. #6
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    that's what I was getting at. A temp/second file that you will make the altered copy in. There isn't really any way to pull a small piece out of an existing file such that everything collapses together. That's what I think you were looking for.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  7. #7
    Unregistered
    Guest

    Thanks

    I figured I might have to create a new file but I was hoping to get around it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. problems with overloaded '+' again
    By Brain Cell in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2005, 05:13 PM
  5. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM