// 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.IO; namespace E { public class MainClass { public static void MultiReplacer(string infnm, string outfnm, string[] keys, string[] values) { StreamReader sr = new StreamReader(infnm); StreamWriter sw = new StreamWriter(outfnm); string line; while((line = sr.ReadLine()) != null) { for(int i = 0; i < keys.Length; i++) { line = line.Replace(keys[i], values[i]); } sw.WriteLine(line); } sr.Close(); sw.Close(); } public static void Main(string[] args) { string[] keys = { "key1", "key2" }; string[] values = { "value1", "value2" }; MultiReplacer(@"C:\a.txt", @"C:\b.txt", keys, values); } } }