Q:

When should you start using string replace over sprintf?

To start off, I may be using sprintf in the wrong manner.
I'm making a framework plugin that takes strings as configuration. The strings have things that need to be swapped out, for example, one string would be a path template:
[root]/[template_directory]/something/specific/[theme_name].htm

The example above is pretty specific and has a lot of variables to be swapped out.
For less variables, I've been doing it like so:
sprintf('%s/some/file/path/theme.htm',documentroot);

However, I'm wondering if sprintf might be more obscure to use for more variables.
In the first example, should I be using a string replace for each variable, or should I use sprintf? Or am I horribly using sprintf wrong?
Any advice is greatly appreciated!

A:

Maybe you could use replace in std::string:
Please look at this examples:
http://www.devx.com/getHelpOn/10MinuteSolution/16972/1954
std::string phrase = "[root]/[template_directory]/something/specific/[theme_name].htm";
std::string sought = "[root]";
std::string replacement = "newROOT";

phrase.replace(phrase.find(sought), 
               sought.size(), 
               replacement);

Good luck!

