落木萧萧 发表于 2008-6-9 21:52

请指点一二...

using System;
using System.IO;
class A
{
    public static void Main(string[] args)
    {
        FileStream fs = new FileStream(@"f:\test.txt", FileMode.Open, FileAccess.Read);
        StreamReader sr = new StreamReader(fs);
        sr.BaseStream.Seek(0, SeekOrigin.Begin);
        string str1 = sr.ReadLine();
        string[] str2=new string[10];
        int x;
        int Count = 0;
        while (str1 != null)
        {
            str1 = sr.ReadLine();
            x = str1.IndexOf("T");
            str2[Count] = str1.Substring(x, 3);
            Count++;
        }

        for (int i = 0; i < Count;i++ )
        {
            Console.WriteLine(str2[i]);
        }
    }
}
这段代码为什么不能输出'str2'?????
帮忙修改一下...

sunkaidong 发表于 2008-6-9 22:17

using System;
using System.IO;
class A
{
    public static void Main(string[] args)
    {
        FileStream fs = new FileStream(@"f:\\test.txt", FileMode.Open, FileAccess.Read);
        StreamReader sr = new StreamReader(fs);
        sr.BaseStream.Seek(0, SeekOrigin.Begin);
        string str1 = sr.ReadLine();
        string[] str2 = new string[10];
        int x;
        int Count = 0;
        while (str1 != null)
        {
            
            x = str1.IndexOf("T");
            if (x < 0) x = 0;
            str2[Count] = str1.Substring(x, 3);
            Count++;
            str1 = sr.ReadLine();
        }

        for (int i = 0; i < Count; i++)
        {
            Console.WriteLine(str2[i]);
        }
      
    }
}

落木萧萧 发表于 2008-6-10 09:06

承蒙指教,感激不尽.

高手就是不一样..

页: [1]

编程论坛