int counter = 0;
string line;
System.IO.StreamReader file =new System.IO.StreamReader("1.txt");
while((line = file.ReadLine()) != null)
{
listBox1.Items.Add(line);
int  a=line.LastIndexOf(" ");
listBox1.Items.Add(a.ToString()+"   "+line.Length);
listBox1.Items.Add(line.Substring(a,line.Length)); 
counter++;
}
未处理的“System.ArgumentOutOfRangeException”类型的异常出现在 mscorlib.dll 中。其他信息: 索引和长度必须引用该字符串内的位置。
listBox1.Items.Add(line.Substring(a,line.Length));这句怎么会错?

解决方案 »

  1.   

    我就是要int  a=line.LastIndexOf(" ");a到最后的字符,怎么就不行?
      

  2.   

    你的文件是什么样子的(1.txt),然后你想要什么效果?
      

  3.   

    listBox1.Items.Add(line.Substring(a,line.Length));这句确实会错。你直接写:listBox1.Items.Add(line.Substring(a));就可以了。
      

  4.   

    内容如下:
    2006-10-21 16:44:25        0:12
    2006-10-21 16:45:27        0:45

    StreamWriter sw=new StreamWriter("1.txt",true);
    sw.WriteLine(DateTime.Now.ToString()+"        "+textBox1.Text);
    写入