我保持gettting数组索引超出范围?数组越界?
Iv'e尝试更改mymatches.Count到+1和-1但它仍然超出界限。
为什么?
public string[] readAllScripts()
{
string[] scripts = txt_script.Lines;
int arraysize = scripts.Length;
int x = 0;
int y = 0;
MessageBox.Show(arraysize.ToString());
//string pattern = "[a-zA-Z]*";
string[][] scriptarray = new string[arraysize][];
for (int i = 0; i < scripts.Length; i++)
{
MatchCollection mymatches = Regex.Matches(scripts[i], "[a-zA-Z]*");
scriptarray[i] = new string[mymatches.Count];
foreach (Match thematch in mymatches)
{
scriptarray[x][y] = thematch.Value;
y++;
}
x++;
}
return scripts;
}
你确定你是否得到正则表达式匹配? – Brian 2012-07-23 21:24:47
@布莱恩 - 这里没关系。 'scriptarray [i]'可以很好地保存0个元素的数组。没有理由超越界限。 – 2012-07-23 21:32:30