我想把一个文件夹内的所有文件(其中包含后缀名为.html,.xml,.php)里面的“抛物线”改成“掉了”
怎么改?请教大家!
怎么改?请教大家!
解决方案 »
- 求:Linq算法
- vs2010运行的错误
- C# windows窗体的程序Singleton模式怎么不能控制了?
- 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 ....
- 利用c#桌面程序在一个大循环里从数据库中取出数据处理后更新回数据库里,把这一过程作为一个事务........
- C#调用kodak控件编辑图片的问题
- 如何通过输入某几个汉字的首字母即可取得相应的汉字词组?
- 请问谁见过这个异常S.Internal.FontCache.Util
- 各位大哥帮忙,全部分相送!!!
- datetimepicker的一个现象
- 线程 InvokeRequired老是false
- 求像QQ登陆界面上密码输入时 软键盘代码
string[] extensions = new string[] { "*.html", "*.xml", "*.php" };
foreach (String extension in extensions)
{
string[] paths = System.IO.Directory.GetFiles("目录路径", extension, System.IO.SearchOption.TopDirectoryOnly);
foreach (string path in paths)
{
System.IO.StreamReader sr = new System.IO.StreamReader(path);
string result = sr.ReadToEnd();
sr.Close();
result = result.Replace("抛物线", "掉了");
System.IO.StreamWriter sw = new System.IO.StreamWriter(path, false);
sw.Write(result);
sw.Close();
}
}
读取文件,判断文件后缀f.Extension。
如果是。就读出文件内容。之后用Replace替换。再重新写进去。!
foreach (String extension in extensions)
{
string[] paths = System.IO.Directory.GetFiles("目录路径", extension, System.IO.SearchOption.TopDirectoryOnly);
foreach (string path in paths)
{
System.IO.StreamReader sr = new System.IO.StreamReader(path,System.Text.Encoding.Default);
string result = sr.ReadToEnd();
sr.Close();
result = result.Replace("抛物线", "掉了");
System.IO.StreamWriter sw = new System.IO.StreamWriter(path, false,System.Text.Encoding.Default);
sw.Write(result);
sw.Close();
}
}
其中System.Text.Encoding.Default可以改成你对应的文件编码格式