question: public static String convertNewLines ( String string ) { int index ; StringBuffer newStringBuffer = new StringBuffer ( ) ; while ( ( index = string . indexOf ( '\n' ) ) != - 1 ) { if ( index > 0 ) { newStringBuffer . append ( string . substring ( 0 , index ) ) ; } newStringBuffer . append ( '\\' ) ; newStringBuffer . append ( 'n' ) ; if ( ( index + 1 ) < string . length ( ) ) { string = string . substring ( index + 1 ) ; } else { string = "" ; } } newStringBuffer . append ( string ) ; string = newStringBuffer . toString ( ) ; newStringBuffer = new StringBuffer ( ) ; while ( ( index = string . indexOf ( '\r' ) ) != - 1 ) { if ( index > 0 ) { newStringBuffer . append ( string . substring ( 0 , index ) ) ; } newStringBuffer . append ( '\\' ) ; newStringBuffer . append ( 'r' ) ; if ( ( index + 1 ) < string . length ( ) ) { string = string . substring ( index + 1 ) ; } else { string = "" ; } } newStringBuffer . append ( string ) ; return newStringBuffer . toString ( ) ; }
target:  Converts carriage returns and new lines in a string into \r and \n.