C#正则表达式替换
RegExp,替换字符串
String SourcePath = @"C:\demo";
var files = Directory.GetFiles(SourcePath, "*.cs", SearchOption.AllDirectories);
foreach (var filePath in files)
{
label2.Text = "正在替换:" + filePath + "文件";
foreach (var oldstr in s)
{
File.WriteAllText(filePath, Regex.Replace(File.ReadAllText(filePath), oldstr, "DALService"));
label1.Text = "当前关键字:" + oldstr;
Application.DoEvents();
}
}
MessageBox.Show("替换完毕!");