posted 20 years ago
As of 1.4 String has a replace method that might do the job for you. If you're on an older JVM that doesn't have replace() the usual trick is:
Do you know the "p" part ahead of time? It's easy to search for "predpred" with indexof. If you also have to handle "gredgred" or "shredshred" then I guess you'd have to search for the "red" only. Find it once, then use that position plus one as a start to find it again.
Play with String.indexof and String.substring and see if you can get something going. Feel free to post more code for comment.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi