读取txt正则匹配行写入txt

StreamReader sr = new StreamReader("C:\\Users\\Administrator\\Desktop\\blogbbs\\dd.txt",Encoding.Default);
            StringBuilder sb = new StringBuilder();
            string s = "";
            string patt = "【(.+?)】";
            Regex r = new Regex(patt);
            while((s = sr.ReadLine()) != null)
            {
                if (r.IsMatch(s))
                {
                    Match m = r.Match(s);
                    sb.AppendLine(m.Groups[1].Value);
                }
            }
            File.AppendAllText("C:\\Users\\Administrator\\Desktop\\blogbbs\\123.txt",sb.ToString(),Encoding.Default);

 

posted @ 2014-08-16 09:53  跟着阿笨一起玩.NET  阅读(988)  评论(0编辑  收藏  举报