Inserting, deleting, or modifying the contents of a text file pretty much follows this basic procedure:
1. Open two files, the text file as the input for reading, and a new temporary file for output to write to.
2. Read the input file, line by line, and write it to the output file, doing whatever else you need to do:
a. If you need to insert something before that line, then write it to the output file before you write that line you input.
b. If you need to delete that line, then do not write it out to the output file.
c. If you need to modify that line, then modify it and then write it to the output file.
3. When you are done, then close both files, delete the input file, and rename the temporary output file to the input file's old name.
And that's how you do it.
| Also while im at it, is it possible to take 2 separate .txt docs..lets say one is filled with the names of documents and the other is filled with links to the document, can you join them together, while placing lets say html or css(doesn't matter just string in general) code/tags at the beggining of the line, in between the title's and links of the documents and at the end also? |
Yes, of course it's possible. That is exactly how we used to generate dynamic web pages with CGI (Common Gateway Interface).
You know how to write text files and you know how to read text files, so you just need to incorporate what you read with what you're writing. Could possibly get a bit tedious, but entirely doable.