Say I have a text template with a number of fields that need to be populated:

var template = "hello {$name}. you are {$age} years old. you live in {$location}"

and an IDictionary<string,string> of values to substitute:

key     | value
===================
name    | spender
age     | 38
location| UK

The naive way of populating the template might be something like:

var output = template;
foreach(var kvp in templValues)
{
    output = output.Replace(string.format("{{${0}}}", kvp.Key), kvp.Value);
}

However, this seems painfully inefficient. Is there a better way?

Edit
Report