using System; using System.Collections; using System.Text.RegularExpressions; class test { static Hashtable hash = new Hashtable(); static void Main () { hash.Add("a", "abc"); hash.Add("d", "def"); hash.Add("g", "ghi"); string text = "%a% %d% %g%"; Console.WriteLine( "Before: {0}", text ); Console.WriteLine( "After : {0}", fillTemplate( text ) ); } static string fillTemplate ( string text ) { return Regex.Replace( text, @"%(?\w)%", new MatchEvaluator( hashLookup ) ); } static string hashLookup ( Match m ) { return (string)hash[m.Groups["templ"].Value]; } }