Do not loop through the string, my code returns the first index of a newline.