public static String removeNewLines ( String textContent ) { if ( textContent == null ) { return "" ; } StringBuilder s = new StringBuilder ( ) ; boolean inNl = false ; for ( char c : textContent . toCharArray ( ) ) { if ( c == ' ' ) { if ( ! inNl ) { s . append ( ' ' ) ; inNl = true ; } } else { inNl = false ; s . append ( c ) ; } } return s . toString ( ) ; }
Replace multiple newline characters with a single space .