-1

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.

Mostafiz
  • 7,243
  • 3
  • 28
  • 42
Bootsie123
  • 161
  • 1
  • 13
  • 4
    [File.ReadAllText](https://msdn.microsoft.com/en-US/library/system.io.file.readalltext(v=vs.110).aspx) and [String.Replace](https://msdn.microsoft.com/en-Us/library/system.string.replace(v=vs.110).aspx) – Mark Aug 21 '16 at 16:43
  • I have the code that gets the string to replace the "@@"s with. I just don't know like how to do it/where to go next. I did look at using StreamWriter although I'm not sure how to use it to do what I would like. – Bootsie123 Aug 21 '16 at 16:47
  • 1
    When you get access to internet beyond SO please consider searching before asking here - https://www.bing.com/search?q=c%23+read+write+text+file (or similar searches on other search engines) would give you answer. – Alexei Levenkov Aug 21 '16 at 16:50

1 Answers1

2

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);
Mostafiz
  • 7,243
  • 3
  • 28
  • 42