That happens because you have two consecutive words that are the same, or at least the second word is contained in the first one. So the second time that you do "index = f.IndexOf(firstWord, index)" you will have the exact same index as the time before, or at least you wont be out of the first word. For instance, first word is "pleasure" second word is "sure".
To avoid that you can update index to never go back, please replace the following line:
index = f.IndexOf(firstWord, nextIndex);
I don't know what exactly you want this algorithm to do... so this might not work as you think it should.
No comments:
Post a Comment