First problem: you didn't instanciate the
projects
array. And it looks like you don't need an array here but a list (since you don't know the total number of elements added into
projects
).
You should replace:
array<String^>^ projects;
by:
List<String^>^ projects = gcnew List<String^>();
And in you while loop, replace:
projects[jamrod] = splitx[ok];
by:
projects->Add(splitx[ok]);
Second problem: what is the
yes
string supposed to contain? It is like you expect it to contain at least
"3D"
, right? Otherwise your
while
loop would never exit... Unless you give more details about
yes
, I can't help further.
-----------------------------------
If I understood well, you want to split a string into sub-strings (separated by
' '
) and collect every sub-strings between
"Copyright"
and
"3D"
. If I am right, then use this code:
Document ^doc = gcnew Document("Abdul.doc");
String ^yes = doc->GetText();
array<Char>^ chars = gcnew array<Char>(1) { ' ' };
array<string^>^ splitx = yes->Split(chars);
List<string^>^ projects = gcnew List<string^>();
bool foundStart = false;
for (int i = 0; i < splitx->Length; i++)
{
if (splitx[i] == "3D")
{
break;
}
if (foundStart)
{
projects->Add(splitx[i]);
}
else
{
foundStart = (splitx[i] == "Copyright");
}
}
Otherwise, please explain one more time what you want to achieve.