Hey, I'm sorry for being such a python newb, but thanks for helping me out with the last one! Hopefully you guys will help a newb out again :)

This time, I need to use a recursive function to basically do the same thing that the .replace function for strings in python does. Problem here is, yet again, I have no idea how to attack this problem.

My idea is to maybe shorten the original string by one index with each recursive call and add the replacement string once the old string has been cut out, but the problem is, I don't know how to save any letters prior to the substring to not permanently get rid of the pieces I need to put the string back together with the new string in place of where the old string used to be.

I wish I could provide atleast some sort of code, but I honestly have absolutely no idea how to even start this one, with the exception of the base condition:

if string==""
return

any help would be greatly appreciated! Thank you!

PS a sample run and desired output should look something like this:

% replace_recursion("stringproblem","problem","solution")
% "stringsolution"

Once again, thanks for any input or help! Ideas are appreciated greatly too!

nevermind i got it!! probably wont do too much help publishing the code, but if anyone wants it feel free to pm me :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.