public static List < String > splitLines ( String S ) { List < String > V = new ArrayList <> ( ) ; int start = 0 ; int pos ; while ( ( pos = S . indexOf ( ' ' , start ) ) != - 1 ) { String line ; if ( pos > start && S . charAt ( pos - 1 ) == ' ' ) line = S . substring ( start , pos - 1 ) ; else line = S . substring ( start , pos ) ; V . add ( line ) ; start = pos + 1 ; } int slen = S . length ( ) ; if ( start < slen ) { // Ignore any trailing '\r' if ( S . charAt ( slen - 1 ) == ' ' ) slen -- ; String line = S . substring ( start , slen ) ; V . add ( line ) ; } return V ; }
Splits a String into lines on any \ n characters . Also removes any ending \ r characters if present