Bootsie123 Bootsie123 - 1 year ago 97
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 Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download