2012-10-24 12:48:22,911 [0x00005c44] INFO  root -  倾斜, X =-0.070 ,Y=-0.020
2012-10-24 12:48:24,067 [0x00005c44] INFO  root -  气隙,高度=26.080
2012-10-24 12:48:25,090 [0x00005c44] INFO  root -  倾斜, X =-0.080 ,Y=0.050
2012-10-24 12:48:38,855 [0x00005c44] INFO  root -  桩腿- 1 , 高度 =34.428 Num = -861
2012-10-24 12:48:42,517 [0x00005c44] INFO  root -  桩腿- 2 , 高度 =36.254 Num = 92
2012-10-24 12:48:43,523 [0x00005c44] INFO  root -  桩腿- 3 , 高度 =29.772 Num = -4187
2012-10-24 12:48:44,552 [0x00005c44] INFO  root -  气隙,高度=26.080
2012-10-24 12:48:45,562 [0x00005c44] INFO  root -  倾斜, X =-0.150 ,Y=-0.020
2012-10-24 12:48:46,595 [0x00005c44] INFO  root -  桩腿- 1 , 高度 =34.428 Num = -861
2012-10-24 12:48:47,600 [0x00005c44] INFO  root -  桩腿- 2 , 高度 =36.251 Num = 91
2012-10-24 12:48:48,606 [0x00005c44] INFO  root -  桩腿- 1 , 高度 =34.427 Num = -862这是 A.TXT 中的  我想把  带“桩腿”关键字的  行 都存到 B.TXT 中。  谢谢大家了。  

解决方案 »

  1.   

     string sAPath = "D:\a.txt";
                StringBuilder sbNew = new StringBuilder();
                using (FileStream fs = new FileStream(sAPath, FileMode.Open, FileAccess.Read))
                {
                    using (StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("GB2312")))
                    {
                        while (sr.Peek() > 0)
                        {
                            string sCurrentLine = sr.ReadLine();
                            if (sCurrentLine.Contains("桩腿"))
                            {
                                sbNew.AppendLine(sCurrentLine);
                            }
                        }
                    }
                }            using (StreamWriter sw = new StreamWriter("D:\b.txt", true, Encoding.GetEncoding("GB2312")))
                {
                    sw.Write(sbNew.ToString());
                }
      

  2.   

                string[] lines = File.ReadAllLines("c:/test.txt",Encoding.Default);
                for (int i = 0; i < lines.Count(); i++)
                {
                    if (lines[i].Contains("桩腿"))
                    {
                        File.AppendAllText("c:/test2.txt", lines[i]+"\n");
                    }
                }
      

  3.   


    这个写的时候 没运行 不要意思
    string sAPath = "D:\a.txt";
     换成 string sAPath = @"D:\a.txt";路径字符串前边 加一个 @ 
      

  4.   


     我试了下 读取不到哦。是不是 要int sa = timer.IndexOf("111");  用匹配下?
      

  5.   


    不用indexOf把你上边的内容 放在d:\a.txt中再把我的代码 放到一个事件中运行一下 就看到 D盘 根目录下边 b.txt 里边全是带  桩腿 的行我第一次贴的代码 有两个路径 a.txt 和 b.txt  在前边  加一个 @符号
      

  6.   


    #4的代码 也是对的   只是 把 \n  换成 \r\n  就完美了
      

  7.   

    ile.WriteAllLines(@"C:\test2.txt",File.ReadAllLines(@"C:\test1.txt",Encoding.GetCoding("GB2312")).Select(x=>x.Contains("桩腿")).ToArray());
      

  8.   


    File.WriteAllLines(@"C:\test2.txt",File.ReadAllLines(@"C:\test1.txt",Encoding.GetCoding("GB2312")).Where(x=>x.Contains("桩腿")).ToArray());