Your removeNextWord()
method is greedy i.e. it's removing the numbers as well.
In your implementation, you first remove everything that's not a letter before the word, then the word itself and then finally all the characters following the word that are not letters which then removes the id numbers as well.
Perhaps, you should uncomment this line and rename isLetter()
to isToken()
.
(ch >= '0') && (ch <= '9') || // allow numbers
EDIT: Please fix your conditional check for numbers. ch <= '1'
is incorrect.