public static String escapeNewlines ( String str ) { final int len = str . length ( ) ; StringWriter out = new StringWriter ( len * 2 ) ; for ( int i = 0 ; i < len ; i ++ ) { char c = str . charAt ( i ) ; switch ( c ) { case ' ' : out . write ( ' ' ) ; out . write ( ' ' ) ; break ; case ' ' : out . write ( ' ' ) ; out . write ( ' ' ) ; break ; default : out . write ( c ) ; } } return out . toString ( ) ; }
Escapes new line characters of a given string . It also escapes the forward slash characters .