[Solved] Replacing a certain word in a text file

If you don’t care about memory usage: string fileName = @”C:\Users\Greg\Desktop\Programming Files\story.txt”; File.WriteAllText(fileName, File.ReadAllText(fileName).Replace(“tea”, “cabbage”)); If you have a multi-line file that doesn’t randomly split words at the end of the line, you could modify one line at a time in a more memory-friendly way: // Open a stream for the source file using (var … Read more