求字符串子串时的错误?

junsheng junsheng 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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));这句怎么会错?
...全文
评论 10
收藏 已收藏
分享
返回顶部
junsheng
C# 111,129 成员 642,540 内容