2012-10-24 12:51:53,838 [0x00005c44] INFO  root -  桩腿- 2 , 高度 =36.235 Num = 85
2012-10-24 12:51:53,911 [0x00005c44] INFO  root -  倾斜, X =0.060 ,Y=-0.020
2012-10-24 12:51:54,267 [0x00005c44] INFO  root -  桩腿- 1 , 高度 =34.358 Num = -907
2012-10-24 12:51:54,567 [0x00005c44] INFO  root -  水深 深度=34.157
2012-10-24 12:51:54,723 [0x00005c44] INFO  root -  气隙,高度=25.537
2012-10-24 12:51:54,911 [0x00005c44] INFO  root -  倾斜, X =-0.040 ,Y=-0.070
2012-10-24 12:51:55,557 [0x00005c44] INFO  root -  水深 深度=63.515
2012-10-24 12:51:55,723 [0x00005c44] INFO  root -  气隙,高度=25.537
2012-10-24 12:51:55,879 [0x00005c44] INFO  root -  桩腿- 2 , 高度 =36.235 Num = 85
2012-10-24 12:51:55,908 [0x00005c44] INFO  root -  倾斜, X =-0.040 ,Y=-0.010
2012-10-24 12:51:56,133 [0x00005c44] INFO  root -  桩腿- 3 , 高度 =29.427 Num = -4412
2012-10-24 12:51:56,309 [0x00005c44] INFO  root -  桩腿- 1 , 高度 =34.358 Num = -907
2012-10-24 12:51:56,564 [0x00005c44] INFO  root -  水深 深度=35.443
2012-10-24 12:51:56,723 [0x00005c44] INFO  root -  气隙,高度=25.537
2012-10-24 12:51:56,911 [0x00005c44] INFO  root -  倾斜, X =-0.080 ,Y=-0.050
2012-10-24 12:51:57,724 [0x00005c44] INFO  root -  气隙,高度=25.537
2012-10-24 12:51:57,910 [0x00005c44] INFO  root -  倾斜, X =0.060 ,Y=0.020
2012-10-24 12:51:57,920 [0x00005c44] INFO  root -  桩腿- 2 , 高度 =36.235 Num = 85
2012-10-24 12:51:58,174 [0x00005c44] INFO  root -  桩腿- 3 , 高度 =29.424 Num = -4414
2012-10-24 12:51:58,350 [0x00005c44] INFO  root -  桩腿- 1 , 高度 =34.358 Num = -907
2012-10-24 12:51:58,560 [0x00005c44] INFO  root -  水深 深度=24.835
2012-10-24 12:51:58,723 [0x00005c44] INFO  root -  气隙,高度=25.537
我只要  带  “倾斜” 的行。。  求源代码。。  C#初学者。。  尽量 解释 清楚点。。 谢谢 了。c# 文件 txt  提取c#文件提取

解决方案 »

  1.   

    streamreader去readline,自己判断
      

  2.   

      StreamReader sr = new StreamReader("A.txt", Encoding.Default);        FileStream fs = new FileStream("B.txt",
                FileMode.Create, FileAccess.Write, FileShare.None);        StreamWriter sw = new StreamWriter(fs, Encoding.Default);  
           
                 string strLine = sr.ReadLine();
                  while (strLine != null)
                  {
                       if(strLine.IndexOf("root -  倾斜")>0)
                          sw.WriteLine(strLine);
                       strLine = sr.ReadLine();
                  }
    sr.Close();
    sw.Close();
    fs.Close();
      

  3.   

    如果你每次是往B.txt里插入而不是创建,则需要把上面的FileMode.Create改成FileMode.OpenOrCreate FileStream fs = new FileStream("B.txt",
                    FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
      

  4.   


    我在from 里面 加了一个按钮    调试后 点按钮 就执行 你的代码 为啥说“路径中有非法字符”呢?
      

  5.   

    Encoding encoding = Encoding.GetEncoding("gb2312");
    string[] lines = File.ReadAllLines(@"c:\test.txt", encoding).Where(x => x.Contains("倾斜")).ToArray();
    File.WriteAllLines(@"c:\test2.txt", lines, encoding);
    特别要注意编码方式一定要正确,否则找不到“倾斜”。
      

  6.   

     string str = string.Join("\r\n", File.ReadAllLines("D:\\1.txt", Encoding.Default).Where(t => Regex.IsMatch(t, @"root\s*\-\s*倾斜")).ToArray());
                File.WriteAllText("D:\\2.txt", str);
               
      

  7.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;namespace WindowsFormsApplication6
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
             
                         
                StreamReader sr = new StreamReader("e:\a.txt", Encoding.Default); FileStream fs = new FileStream("e:\b.txt", FileMode.Create, FileAccess.Write, FileShare.None); StreamWriter sw = new StreamWriter(fs, Encoding.Default); string strLine = sr.ReadLine(); while (strLine != null) { if (strLine.IndexOf("root -  倾斜") > 0)                      sw.WriteLine(strLine); strLine = sr.ReadLine(); } sr.Close(); sw.Close(); fs.Close();
               
            }
        }
    }你看看我的代码  我运行也没错的 但是 一点 按钮  就弹出来 说 路径中有非法字符
      

  8.   

    路径中的\符号要转义
    把("e:\a.txt",改成("e:\\a.txt",e:\b.txt也改成e:\\b.txt   StreamReader sr = new StreamReader("e:\\a.txt", Encoding.Default); FileStream fs = new FileStream("e:\\b.txt", FileMode.Create, FileAccess.Write, FileShare.None); StreamWriter sw = new StreamWriter(fs, Encoding.Default); string strLine = sr.ReadLine(); while (strLine != null) { if (strLine.IndexOf("root -  倾斜") > 0)                      sw.WriteLine(strLine); strLine = sr.ReadLine(); } sr.Close(); sw.Close(); fs.Close();
      

  9.   


    谢谢哈。是我的错。 有个文件不是 txt格式的。。 原来 自己写那个也行的。  谢谢哈。 一会给分
      

  10.   


    谢谢哈。 我这边出错了。 格式问题。。win7 那个扩展名隐藏了。 开始没注意。