someone please help me to write a program that would replace all occurances of a substring in a string ,with a given string.if the input string is "the the the the",& if the substring to be deleted & the substring to be substituted are "th",&"ase" respectievely then the output should be something like this,"asee asee asee asee".that is it is not a word by word or character by character replacement.well that makes the whole thing a bit complicated.please help me with this as i have my programing practical exam this wednesday.

"the fat cat"
Replace "fat" with "thin"

Searching for "fat" gets you 3 substrings
pre = "the "
match = "fat"
post = " cat"

Append pre to the result
Append "thin" to the result.
If post also contains "fat", then go round again, otherwise append post and you're done.