// 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.Text; namespace E { class MainClass { public static string QReplace(string s, char fnd, char rpl) { StringBuilder sb = new StringBuilder(); bool inq = false; for(int i = 0; i < s.Length; i++) { if(s[i] == '"') { inq = !inq; } if(s[i] == fnd && inq) { sb.Append(rpl); } else { sb.Append(s[i]); } } return sb.ToString(); } public static void Main(string[] args) { string s = "\"a\"\n\"b\nb\""; Console.WriteLine(s); Console.WriteLine(s.Replace('\n', '#')); Console.WriteLine(QReplace(s, '\n', '#')); } } }