end the indexOf search when there are not enough chars left