'Find and Replace' Problem

Hi everyone,

Before I start this problem/task, I thought I'd touch base here to get some suggestions in case I start on the wrong track.

This is the problem:

I need to open input.txt file and replace every word between quotations e.g.

"print" (note: this word will vary and will be any length)

with the following

Idioma.getTexto("print")

I also need to copy the original "print" into a list.txt as a record of all words replaced.

My plan is as follows:

- Open input.txt
- Search for the first quotation mark (")
- Copy everything from the first quotation mark to the next quotation mark (inclusive) into a buffer.
- Copy the word from that buffer into list.txt
- Then replace the "print" in the input.txt file with Idioma.getTexto("print")

The purpose of this program is to simply avoid having to perform the above task by hand on many many lines and files of code!

Does this seem like the best way to do this? Alternative suggestions most welcome.

Thanks
Don't replace things. What if Idioma.getTexto("print") is longer than "print"? Are you going to shift the whole file?
The right thing to do is to generate output.txt

- Open input.txt, output.txt, list.txt
- Copy characters from input to output until you find "
- Copy characters from input to buffer until you find another "
- Write buffer to list and Idioma.getTexto(buffer) to output

This could be done with two nested loops or a single loop and a state variable.
Topic archived. No new replies allowed.