【发布时间】:2018-05-02 22:05:51
【问题描述】:
string[] hay = GetAllLines(filename);
string needle = txtToonTotTekst.Text;
string alertmsg = "";
string msg = "";
int keywordfound = 0;
int lineno = 0;
while (lineno <= hay.Length)
{
msg += hay[lineno];//msg = msg + hay[lineno];
lineno++;
if ((hay[lineno].IndexOf(needle) == -1))
{
keywordfound = 0;
continue;
}
else
{ /*this means search word was found */
keywordfound = 1;
alertmsg = msg;
//if coffee found in search string
}
if (keywordfound == 1)
{
alertmsg = msg;
}
lineno++;
}
if (alertmsg == "")
{
alertmsg = "Keyword not found";
}
SchrijfUitvoer("Tekst tonen tot zoektekst + "txtToonTotTekst.Text, alertmsg);
我的问题是关于索引超出数组范围的错误.....通常,当您输入要搜索的单词时,它会显示文本文件中的文本,并在找到搜索词时显示行数
【问题讨论】:
-
你能提供错误信息吗?它指向哪一行(堆栈跟踪)?
-
if ((hay[lineno].IndexOf(needle) == -1))
-
hay[] 是一个数组
标签: arrays string while-loop textbox indexoutofboundsexception