Hi,

Im trying to loop through a string to get all layout of words in a forward manner and then search for patterns elsewhere.

I first created this:

spacePos.push_back(0);
for(int j = 0; j<input.length()+1; j++)
{
if (input[j] == char(32) || j == input.length())
{
spacePos.push_back(j);
}
}

basically pushes integers onto a vector of ints, with the start and end position, and also where any spaces are.

Then i try ot loop as so:

for(vector::iterator ii = spacePos.begin(); ii!=spacePos.end(); ii++)
{
for(vector::iterator ii2 = spacePos.begin(); ii2!=spacePos.end(); ii2++)
{
if (*ii2 == 0 || *ii >= *ii2) continue;

if (input.substr(*ii, *ii2) != "")
{
//other code
}
}
}

so if the input line was "hello i am" it would 'hopefuly' do this:

"hello"
"hello i"
"hello i am"
"i"
"i am"
etc

but the problem is, i'm counting the spaces in the first for loop and storing them and after the first iterator of the for loop for ii, it's going out of sync and the longer the string the more this affect occurs:

"hello"
"hello i"
"hello i am"
" i"
" i am"

i tried trimming but it just causes so many problems with long strings so i really want to sort this out in the first for loop where i obtain all the space positions.

Does anyone have any ideas? or maybe even a better way to do what i want?

Cheers