Find line break in formula field

Make a Custom Setting, type Hierarchy. This setting needs to have a field in it that has the value:

a
b

In this answer, my custom setting is Global__c and my field is CRLF__c.

What characters you use doesn't matter, but the important thing is one character on the first line, and one character on the second line. The Length of this custom setting is actually 4 characters. Two printable, a and b, and two that don't have a glyph, Carriage Return aka CR aka \r and Line Feed aka LF aka \n.

MID($Setup.Global__c.CRLF__c, 3, 1) is now equivalent to a Line Feed character in the context of a formula. We can abuse this to do things like get the first line of an address field.

IF(
  CONTAINS(MailingStreet, MID($Setup.Global__c.CRLF__c,3,1)), 
  LEFT(
    MailingStreet, 
    FIND(MID($Setup.Global__c.CRLF__c,3,1), MailingStreet)
  ),
  MailingStreet
)

You could try something to the effect of:

String Line1, Line2, Line3;
String[] lines = addressFormula.split('\r\n');
Line1 = lines[0];
if (lines.size() > 1){
    Line2 = lines[1];
    if (lines.size() > 2){
        Line3 = lines[2];
    }
}