Fork me on GitHub

批量修改文件内容

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();

        }
    }
}

 

posted @ 2016-03-20 12:00  千秋此意  阅读(292)  评论(0编辑  收藏  举报