我有一个for循环,将数组中的项添加到listView。IndexOutOfRangeException was unhandled-索引超出了数组的边界
(它会抢在网页上的项目,之后删除任何东西“的字符串,然后将它添加到ListView)
我得到的错误是:IndexOutOfRangeException was unhandled- Index was outside the bounds of the array
这里是我的代码现在用:
string[] aa = getBetweenAll(vid, "<yt:statistics favoriteCount='0' viewCount='", "'/><yt:rating numDislikes='");
for (int i = 0; i < listView1.Items.Count; i++)
{
string input = aa[i];
int index = input.IndexOf("'");
if (index > 0)
input = input.Substring(0, index);
listView1.Items[i].SubItems.Add(input);
}
出现的错误在这条线:string input = aa[i];
什么我做错了什么?我该如何解决这个问题,以便它会停止发生?谢谢!
如果你想知道的getBetweenAll方法的代码是:
private string[] getBetweenAll(string strSource, string strStart, string strEnd)
{
List<string> Matches = new List<string>();
for (int pos = strSource.IndexOf(strStart, 0),
end = pos >= 0 ? strSource.IndexOf(strEnd, pos) : -1;
pos >= 0 && end >= 0;
pos = strSource.IndexOf(strStart, end),
end = pos >= 0 ? strSource.IndexOf(strEnd, pos) : -1)
{
Matches.Add(strSource.Substring(pos + strStart.Length, end - (pos + strStart.Length)));
}
return Matches.ToArray();
}
请出示什么getBetweenAll的方法或函数看起来像 – MethodMan
@DJKRAZE我张贴现在 –