Yes, split your input only once, on once every time loop is executed:
wholepage = streamReader.ReadToEnd();
var split = wholepage.Split();
while (true)
{
tempword = split[tempnum];
// (...)
}
And btw. you doesn't stop your loop so it potentially never ends (well, actually it does, when index is greater than number of items in array and exception is thrown). You should probably use foreach
instead of while
:
wholepage = streamReader.ReadToEnd();
var split = wholepage.Split();
foreach(var tempword in split)
{
if(lastword == "NUM")
{
things[number_of_things].num = tempword;
number_of_things++;
slist.Add(new string[] { tempword });
listBox5.Items.Add(tempword);
}
lastword = tempword;
}