Results 1 to 2 of 2

Thread: Help with C# and Text File

  1. #1
    Join Date
    May 2010
    Rep Power

    Exclamation Help with C# and Text File

    I am helping a friend with a project. He is currently having trouble deleting information from the text file, He is able to add and update information just fine but deleting is the prob. Anyone has any suggestions?
    CLICK-> Online Gamer Tags ** Job - Senior Dynamics 365 Consultant ** CLICK-> Surface Pro 4 128GB || DESKTOP-> IF THE TRUTH HURTS CLOSE THE THREAD
    If being a nerd means I make more money than you by just walking into a room, while still having a wife and social life... then it SUCKS To Be YOU !

  2. #2
    Join Date
    May 2003
    Rep Power


    I have an algorithm he can try.

    Imagine that the file is divided in three parts.
    1. The text before the text to be deleted (let's call this text BEFORE).
    2. The text to be deleted (let's call this text TO-BE-DELETED).
    3. The text after the text to be deleted (let's call this text AFTER).

    So the text file looks like this


    Of course, this division is imaginary, I only use it so I can describe the algorithm easily.

    The algorithm is:
    1. Update the text that starts from TO-BE-DELETED with a copy of the text from AFTER.
    2. Truncate the file after the updated text.

    This looks like a student project so I don't know how solid you want to make this but you might want to consider the possibility that any (and maybe all?) parts of the file could be empty. For example, the text to be deleted could be at the end of the file (in which case AFTER is empty).
    You might also want to be aware that if AFTER is longer than TO-BE-DELETED then the update is going to run into AFTER.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts