public static String replaceNewLines ( String src , int from , int to ) { if ( src != null && from > 0 && to < from ) { String strFrom = "" ; String strTo = "" ; for ( int i = 0 ; i < from ; i ++ ) { strFrom += "\n" ; } for ( int i = 0 ; i < to ; i ++ ) { strTo += "\n" ; } while ( src . contains ( strFrom ) ) { src = src . replaceAll ( strFrom , strTo ) ; } } return src ; }
Replaces successive new line characters .