我的txt文件形式是这样的:
001/t abc/n
002/t def/n
003/t ghi/n我要进行的操作是:对/t之前的内容(比如001)进行搜索,如果匹配的话返回后面的内容(比如abc)

解决方案 »

  1.   

    ScreamReader读取出来,之后放到Directory<key,value>里面,之后遍历
      

  2.   

    好像没有搜索txt文本的方法,只有逐行或者全部读取到内存,然后处理。
      

  3.   

    逐行读出来读出来后,使用Split分解一下,前面相同,则返回后面的字符串
      

  4.   


    using System.IO;
     StreamReader sr = new StreamReader(@"E:\WebPage\2011-04-12\248808221\250167153.txt");//你的txt文件路径
                string rowstring = "";
                while (sr.Peek() > 0)
                {
                    rowstring = sr.ReadLine();// 获取当前行字符串
                      string str1=rowstring.SubString(0,3);//
                    if(str1="你要的数字")
                      {
                        string str2=rowstring.SubString()//截取后面的字符串
                            break;
                      }
                  }
                sr.Close();
      

  5.   

    引用楼上修改
    using System.IO;
    StreamReader sr = new StreamReader(@"E:\WebPage\2011-04-12\248808221\250167153.txt");//你的txt文件路径
    string line = string.Empty;
    string result = string.Empty;
    while (sr.Peek() > 0)
    {
        line = sr.ReadLine();// 获取当前行字符串
                      
        if(line.StartWith("001"))
        {
            result = line.SubString(4);//截取后面的字符串
            break;
        }
    }
    sr.Close();
      

  6.   

    字符串截取,你先把文件内容读取到dataset再截取
      

  7.   

     我是这么写的
     public string CorName(string )               {
                StreamReader sr = new StreamReader("ll.txt", Encoding.Default);
                while (sr.Peek() >= 0)
                {
                    .....    
                     return     ;         
                }
                return errorr;
            }