The .NET Framework gives us the Format method:
string s = string.Format(\"This {0} very {1}.\", \"is\", \"funny\");
// s is now: \"This is very funny.\"
Yep. These are called "regular expressions". The one that will do the thing is
This (?<M0>.+) very (?<M1>.+)\.
@mquander: Actualy, PHP solves it even different:
$s = "This is very very funny.";
$fmt = "This %s very %s.";
sscanf($s, $fmt, $one, $two);
echo "<div>one: [$one], two: [$two]</div>\n";
//echo's: "one: [is], two: [very]"
But maybe your regular expression remark can help me. I just need to rewrite "This {0} very {1}."
to something like: new Regex(@"^This (.*) very (.*)\.$")
. This should be done programmatical, so I can use one format string on the public class interface.
BTW: I've already have a parser to find the parameters: see the Named Format Redux blog entry by Phil Haack (and yes, I also want named paramters to work both ways).