Open a file and replace strings in C#

前端 未结 6 892
太阳男子
太阳男子 2020-11-30 04:19

I\'m trying to figure out the best way to open an existing file and replace all strings that match a declared string with a new string, save it then close.

Suggestio

6条回答
  •  不知归路
    2020-11-30 05:06

    Slight improvement on the accepted answer that doesn't require Regex, and which meets the requirements of the question:

    File.WriteAllText("Path", File.ReadAllText("Path").Replace("SearchString", "Replacement"));
    

提交回复
热议问题