Formatting text in String from PDF File

I have extracted text from a page in a PDF file and stored it into a string. The string is formatted in lines to match the PDF text

Would like to know if there is a way go through each line in a loop and compare each line for a string.