// 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; using System.Text; using System.Text.RegularExpressions; public class ScriptReplace : Stream { private Stream real; private Stream temp; public ScriptReplace(Stream real) { this.real = real; this.temp = new MemoryStream(); } public override bool CanRead { get { return false; } } public override bool CanSeek { get { return false; } } public override bool CanWrite { get { return true; } } public override long Length { get { return temp.Length; } } public override long Position { get { return temp.Position; } set { throw new NotSupportedException(); } } public override int Read(byte[] buffer, int offset, int count) { throw new NotSupportedException(); } public override long Seek(long offset, SeekOrigin direction) { throw new NotSupportedException(); } public override void SetLength(long length) { throw new NotSupportedException(); } public override void Close() { temp.Close(); StreamReader sr = new StreamReader(new MemoryStream(((MemoryStream)temp).ToArray()), Encoding.UTF8); StreamWriter sw = new StreamWriter(real, Encoding.UTF8); string line; while((line = sr.ReadLine()) != null) { line = Regex.Replace(line, @"(