C# modify file (read all and modify and write all)

来源:互联网 发布:颂歌java 编辑:程序博客网 时间:2024/05/17 03:07
 StringBuilder newFile = new StringBuilder();
string temp = "";
string[] file = File.ReadAllLines(@"C:/Documents and Settings/john.grove/Desktop/1.txt");
foreach (string line in file)
{
    if (line.Contains("string"))
    {
        temp = line.Replace("string", "String");
        newFile.Append(temp + "/r/n");
        continue;
    }
    newFile.Append(line + "/r/n");
}
File.WriteAllText(@"C:/Documents and Settings/john.grove/Desktop/1.txt", newFile.ToString());
原创粉丝点击