Hi:
how to overwrite the old data in *.txt with only little steps, I did somehow in a very complicated way.
thanx
Printable View
Hi:
how to overwrite the old data in *.txt with only little steps, I did somehow in a very complicated way.
thanx
I guess the easiest way for small files would be read it all into one string, replace what you need, and write it all back.
NVoigt,
What is the best approach for big files? Should I still read, edit and write? How could I seach for a string, position there, and overwrite that string? Any ideas?????
Thanks,
Kendal
Replacing a string in a file is always messy, because you can only do this if the strings lengths' match. Therefore, I would suggest reading the input file line by line, replacing in each line and writing it back to a seperate output file. Once this is done, the input can be deleted and the output renamed to the former input.
If your replacement can span more than one line, the reading/writing part becomes a bit tricky, but basically, the input, copy, delete, rename output would stay the same.
Gotcha,
I appreciate it.
Thanks again,
Kendal