using System.Collections.Generic;
using System.Text.RegularExpressions;
public static void Main(string[] args)
string input = "{entry1} {entry2} this is a string";
Dictionary<string, string> dictionary = new Dictionary<string, string> { { "entry1", "foo" }, { "entry2", "bar" } };
var result = dictionary.ReplaceKeyInString(input);
Console.WriteLine(result);
public static class DictionaryExtensions
public static string ReplaceKeyInString(this Dictionary<string, string> dictionary, string inputString)
var regex = new Regex("{(.*?)}");
var matches = regex.Matches(inputString);
foreach (Match match in matches)
var valueWithoutBrackets = match.Groups[1].Value;
var valueWithBrackets = match.Value;
if(dictionary.ContainsKey(valueWithoutBrackets))
inputString = inputString.Replace(valueWithBrackets, dictionary[valueWithoutBrackets]);