Click to See Complete Forum and Search --> : searching/changing string in a txt file


ryan crey
February 23rd, 2003, 08:17 PM
Hello,

i've a txt file and somewhere inside it i put


------- xxx.txt ---

content content content content content content content content content content content content content content content content content content content content content content content content content content content content $CHANGEME$ content content content content content content content content content

------- xxx.txt ---

what would be the best way to search for $CHANGEME$ inside it and change to something which i will define later? i know how to open/read, but dont know how to search, i could hardcode the offset of $CHANGEME$ but it may vary from file to file

any help is appreciated.
ryan

KingTermite
February 24th, 2003, 08:23 AM
A quick "non OO" way would be to read in as a standard C string and use strstr() to get the pointer to the actual thing you want to change. You can then search for the space or tab to find the end.

Once you have the pointer and the size you can change it to whatever you want, whenever you want.

However, if you want to change it to something of a different size, then it might be easier to use CString class instead. It has a richer OO set of methods that allow the string size to grow dynamically without you having to worry about it.