I have a parent String - say "ABCHASOIOBBASJSKAKSLK" (something like that)
I get input from the user as what replacement must be made for what substring of the parent String.
The user might say 'replace BALL for B' and 'replace APPLE for A' and 'replace IOP for CHA'..... in the parent.
The problem happens when I do serial replacements.That is, when I'm done with my first replacement and proceed over to the second, replace causes all 'A's (including 'A's in the previously replaced 'BALL' also)to be replaced with 'APPLE'..and so on..but what I want to do is just do a replace for whatever is in the parent String. Thats it.
I hope you guys get me.. 'B' in the parent String must be replaced with 'BALL' and 'A's in the parent String alone must be replaced with 'APPLE', 'A' in 'BALL' must remain as such.
For my simple mind the natural approach would be:
- Remember index
- Loop until no replacement keys can be found
- In each loop check all available key positions, replace the smallest with the corresponding value
So all keys should be replaced and the index marker should increase so that already replaced values aren't processed again. Okay, sounds funny, looks funny ... but seems to work ; - )
Censorship is the younger of two shameful sisters, the older one bears the name inquisition. -- Johann Nepomuk Nestroy
Peter, thanks for your reply. I too had almost the same thing in mind - noting down indexes and replacing....but thought there actually must be something out there, that I dont know/I haven't come across..
Sudipta, thanks for your reply. Actually, I'm not sure of the input and as you say some problem might pop up when the string which we use to replace '###' might already be present in the parent string..