比如某个文件中
a      1
b      2
c      3
怎么把1,2,3读出来?

解决方案 »

  1.   

    StreamReader read = new StreamReader(@"c:\1.txt");
    string s =string.Empty;
    string [] ss=null;
    while((s=read.ReadLine())!=null)
    {
      ss=s.Split(new char[]{'\t'});
      foreach(string s1 in ss)
      {
        Console.WriteLine(s1);
      }} 
    read.Close();
      

  2.   

    楼上基本上是正解,只是要完全实现LZ 的需求需要改一下
    StreamReader read = new StreamReader(@"c:\1.txt"); 
    string s =string.Empty; 
    string [] ss=null; 
    while((s=read.ReadLine())!=null) 

      ss=s.Split(new char[]{'\t'}); 
      if(ss.Length==2)
         Console.WriteLine(ss[1]); 
      else
         Continue;
      

  3.   

    哦,刚才写错了,是ss.Length==3
      

  4.   

    参考代码:
    StreamReader sr = new StreamReader(sFileName,Encoding.Default);
    string[] strArray = null;
    string strRead = "";
    string strValue = "";
    if(sr==null) {return;}
    while(sr.Peek()>0)
    {
       strRead = sr.ReadLine();
       if(string.IsNullOrEmpty(strRead)) {continue;}
       strArray = strRead.Split(' ');//' '单引号之间是Tab键
       if(strArray == null || strArray.Length < 2) {continue;}
       strValue = strArray[1]; //strValue即为你需要读取的值
    }
    sr.Close();
      

  5.   

    呃,其实我更想知道的是不针对于我举的例
    而是所有Tab后...
    a      1      55
    b      2      65
    c      3      67
      

  6.   

    一样,只要数据读出来了,然后就有tab来split就可以的