请教各位啊,有一个文本文件,我想先找到指定字符“W1”,然后读出它后面的3行的内容:
文本文件内容格式如下
aa bb cc xx vv aa ff gg
ssssssss ddddddd ffffffff
w1
111 222 333 444 555
666 ttt hhh jjj aaa
... ... ... ... ...
... ... ... ... ...请教要怎么实现啊,请教啦

解决方案 »

  1.   

    string.find
    int i =3;
    while(i>0)
    {
    readline();
    }
      

  2.   

    一行一行读
    判断当前行是否包含w1
    如果包含 把接下来的3行读出来
    或者readToEnd 用正则取
      

  3.   

    StreamReader sr=new StreamReader (path);
    int count=0;
    bool flag=false;
    while((sting s= sr.readLine())!=null)
    {
    if(count>=2)
    {
    break;
    }
    if(flag)
    {
       count ++;
       保存s
    }
    if(s.equels("W1"))
    {
     flag=true;
    }}
      

  4.   

    int i = 0;
    string line = reader.readline();
    while(line!=null&&i<3){
    if(line.contains("w1")){
    line = reader.readline();
    console.writeline(line);
    i++;
    }
    line = reader.readline();
    }