+ Start a Discussion
martin_wumartin_wu 

How to parse text line by line

Hi all,

 

I want to create a custom object with information from an incoming email that has a certain structure. For this purpose, I'd need to go through the body text of the email and parse it line by line. What is the best way of doing this? 

 

Cheers, 

 

Martin

Best Answer chosen by Admin (Salesforce Developers) 
FinnArildFinnArild

Split it into an list with String.split('\n') and iterate over the list.

All Answers

FinnArildFinnArild

Split it into an list with String.split('\n') and iterate over the list.

This was selected as the best answer
martin_wumartin_wu

Cool, this works! Thanks a million. Here is the code in case anyone is interested:

 

  List<String> allLines = new List<String>();
         
          allLines = email.plainTextBody.split('\n');
        
          for ( String line : allLines)
              System.debug(line);

 

Cheers, 

 

Martin