我正在从来自 word 文件的字符串中提取子字符串。index out of range
但是即使子字符串的开始和结束索引小于字符串的长度,我也会收到错误消息。
for(int i=0;i<y.Length-1;i++)
{
if (Regex.IsMatch(y[i], @"^[A]"))
{
NumberOfWords= y[i].Split(' ').Length;
if (NumberOfWords > 5)
{
int le = y[i].Length;
int indA = y[i].IndexOf("A");
int indB = y[i].IndexOf("B");
int indC = y[i].IndexOf("C");
int indD = y[i].IndexOf("D");
//if (indD > 1 && indC > 1)
// breakop2 = breakop2 + '\n' + '\n' + y[i].Substring(indC, indD);
if (indC > 1 && indB > 1)
breakop1 = breakop1 + '\n' + y[i].Substring(indB, indC);
if (indB > 1)
sr = y[i].Substring(indA, indB);
else
sr = y[i];
breakop = breakop +'\n'+'\n'+ sr;
Acount++;
//textBox1.Text = s[i];
check1 = check1 + '\n' + '\n' + y[i];
//i++;
}
}
}