Bootsie123 Bootsie123 - 3 months ago 11
C# Question

How do I write text from one file to another after modification in C#?

If I have a .txt file with


Hello, @@. @@ how are you doing?


how could I copy this from the .txt file and then paste it into another one but replace the "@@"'s with the string.

Answer

You can do by this

string text = System.IO.File.ReadAllText(@"E:\test\a.txt");
string s = text.Replace("@@", "new text");
System.IO.File.WriteAllText(@"E:\test\b.txt", s);