码迷,mamicode.com
首页 > 其他好文 > 详细

C# 操作txt

时间:2014-09-01 20:57:03      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:des   os   ar   文件   2014   sp   amp   on   line   

读取文件

FileStream fs = new FileStream("C:\\Users\\john\\Desktop\\a.txt", FileMode.Open);
读取字符
            StreamReader m_streamReader = new StreamReader(fs);
从0位置开始读
            m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
            string arry = "";

从当前流中读取一行字符
            string strLine = m_streamReader.ReadLine();
            do
            {
                string[] split = strLine.Split(‘,‘);
                string a = split[3];
                string b = split[8];
                if (a.IndexOf("小七孔") == -1)
                {
                    if (b.IndexOf("2014-04-07") != -1)
                    {
                        arry += "AWSASD" + strLine.Substring(7) + "\n";
                    }
                }
  新的流中读取
                strLine = m_streamReader.ReadLine();

            } while (strLine != null && strLine != "");
            string ss = arry;
            m_streamReader.Close();
            m_streamReader.Dispose();
            fs.Close();
            fs.Dispose();
            Console.Write(arry);
            Console.ReadLine();

C# 操作txt

标签:des   os   ar   文件   2014   sp   amp   on   line   

原文地址:http://www.cnblogs.com/xiaocandou/p/3949905.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!