批量修改文件内容
using System; using System.IO; using System.Text; namespace UsefulFunctions { public class Program { static string _line; static int _linesnum; static void Main() { ReviseFileContent(@"C:\Users\Administrator\Desktop\mylist.txt"); Console.WriteLine(_linesnum); Console.ReadKey(); } public static void ReviseFileContent(string path) { var sr = new StreamReader(@"C:\Users\Administrator\Desktop\list.txt", Encoding.Default); var sw = new StreamWriter(@"C:\Users\Administrator\Desktop\mylist.txt"); while (!sr.EndOfStream) //是否读到结尾 { if ((_line = sr.ReadLine()) == null) continue; var ss = _line.Split('.'); var s = ss[0] + "S." + ss[1]; sw.WriteLine(s); _linesnum++; } sw.Close(); sr.Close(); } } }