日期:2014-05-17  浏览次数:21053 次

通过C#程序对TXT文件批量修改,求思路。。。
现在有一大堆txt文件,其中格式如下:
08/13/2013,14:46,534,315
08/14/2013,14:47,733,412
08/14/2013,14:48,142,321
08/15/2013,14:49,321,732
08/15/2013,14:50,231,132
……很多条
需要对每个文件做如下操作:
1、删除当天(例8/15/2013)以前的数据
2、将日期和时间合并为一项:yyyy/mm/dd hh:mm
3、删除倒数第二项数据和逗号
TXT文件修改

------解决方案--------------------
StreamReader sr = new StreamReader("test.txt");
            while (sr.Peek() > -1)
            {
                string line = sr.ReadLine();
                string[] str = line.Split(',');
                string newLine = Convert.ToDateTime(str[0] + " " + str[1]).ToString("yyyy/MM/dd HH:mm") + "," + str[3];

                Console.WriteLine(newLine);
            }