stop checking when substring end reaches the end of first string