Jump to content

(solved) replacing strings on a indcated line of a txt file


Recommended Posts

I would like to know the best way to replace text located on a user-selected line of a text file.  The text doesn't necessarily have to be the whole line of the txt file.  I guess I am also asking about the general behavior of the functions when opened with "append" or "overwrite": If i set the position to a particular line in the text file and then use "Filewrite", if I opened the file with overwrite, will it overwrite the text rather than insert itself at the current position and preserving the text?  I am under the impression that calling filewrite would just insert the data at position and not overwrite (except maybe with the exception or fileWriteline?  Does that overwrite the line of text which contains current position?).  Am I wrong?  The only way I can think of to do this would be to read the file to an array, access the particular portion of the array with the data I want to edit, edit the string, then write the array to the file again using the overwrite flag.  Am I overthinking this?

Edited by MattHiggs
Link to comment
Share on other sites

and if you can provide some real examples, I bet a dollar some stringregexp solutions would appear.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...