// 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.IO; using System.Text.RegularExpressions; namespace E { public class Program { public static string Replace(string input, Dictionary replacements) { string res = input; Regex re = new Regex(@"{(\w+)}"); foreach(Match m in re.Matches(input)) { string id = m.Groups[1].Value; res = res.Replace("{" + id + "}", replacements.ContainsKey(id) ? replacements[id] : ""); } return res; } public static void Main(string[] args) { string input; using(StreamReader sr = new StreamReader("input.html")) { input = sr.ReadToEnd(); } Dictionary replacements = new Dictionary(); using(StreamReader sr = new StreamReader("repl.properties")) { string line; while((line = sr.ReadLine()) != null) { string[] parts = line.Split('='); replacements.Add(parts[0].Trim(), parts[1].Trim()); } } string output = Replace(input, replacements); Console.WriteLine(output); } } }