// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Text.RegularExpressions; namespace E { public class Program { public static string XReplace(string s, Dictionary rpl) { string res = s; Regex re = new Regex("{([^}]+)}", RegexOptions.Compiled); foreach(Match m in re.Matches(s)) { res = res.Replace(m.Groups[0].Value, rpl[m.Groups[1].Value]); } return res; } public static void Main(string[] args) { string text = "Lorem ipsum dolor {currency} sit amet, consectetuer adipiscing elit. Quisque et sem {language} ullamcorper est consequat porta."; Dictionary rpl = new Dictionary(); rpl.Add("currency", "DKK"); rpl.Add("language", "Danish"); rpl.Add("foo", "bar"); Console.WriteLine(text); Console.WriteLine(XReplace(text, rpl)); } } }