using System.Collections.Generic;
using System.Text.RegularExpressions;
private static Regex _regex = new Regex(@"(?<={)(\w+)");
public static void Main()
string line = "My values are {first} and {second}";
var dict = new Dictionary<string, object>()
string formatted = Format(line, dict);
Console.WriteLine(formatted);
public static string Format(string rawMsg, IReadOnlyDictionary<string, object> dict) =>
_regex.Replace(rawMsg, match =>
string placeHolder = match.ToString();
return dict.TryGetValue(placeHolder, out object placeHolderValue)
? placeHolderValue.ToString() : null;