Read all file content. Make a replacement with String.Replace
. Write content back to file.
string text = File.ReadAllText("test.txt");
text = text.Replace("some text", "new value");
File.WriteAllText("test.txt", text);
More Related Contents:
- How to check for file lock? [duplicate]
- How to add a Timeout to Console.ReadLine()?
- Reading large text files with streams in C#
- Calculate the execution time of a method
- Cannot delete directory with Directory.Delete(path, true)
- How to read a large (1 GB) txt file in .NET?
- What is the difference between Directory.EnumerateFiles vs Directory.GetFiles?
- An elegant way to consume (all bytes of a) BinaryReader?
- Adding a Line to the Middle of a File with .NET
- How to find out if a file exists in C# / .NET?
- Does FileStream.Dispose close the file immediately?
- How can I split (copy) a Stream in .NET?
- Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required
- What is the purpose of the “Prefer 32-bit” setting in Visual Studio and how does it actually work?
- How to get index using LINQ? [duplicate]
- What is the purpose of self tracking entities?
- C# Point in polygon
- Execute specified function every X seconds
- Async process start and wait for it to finish
- Can you configure log4net in code instead of using a config file?
- Enumerating through an object’s properties (string) in C#
- JIT compiler vs offline compilers
- What is the best way to get the executing exe’s path in .NET?
- How to write an image from byte[] into MS WORD using C# Windows application
- When is “using” block used for in C#? How to use “using” block in C#?
- When is ReaderWriterLockSlim better than a simple lock?
- Self deletable application in C# in one executable
- CryptographicException “Key not valid for use in specified state.” while trying to export RSAParameters of a X509 private key
- Storyboards can’t find ControlTemplate elements
- EPPlus – LoadFromCollection – Text converted to number