I have a dictionary of replacements
var substitutions = new Dictionary<string, string>()
{
{ "one", "two" },
{ "two", "three" },
};
I want to turn the string "one two three four" into "two three three four".
Running any kind of iterative replacement chain like
var phrase = "one two three four";
substitutions.Aggregate(phrase, (current, substitution) => current.Replace(substitution.Key, substitution.Value)));
or
var sb = new StringBuilder(phrase);
foreach (var entry in substitutions)
{
sb.Replace(entry.Key, entry.Value);
}
sb.ToString();
yields "three three three four" because the second replacement "two" → "three" is able to see the "one" → "two" output from the previous output.
How can I only replace "original" words?