public static String revertNewLines(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('\n');
    if ((index + 2) < string.length()) {
      string=string.substring(index + 2);
    }
 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('\r');
    if ((index + 2) < string.length()) {
      string=string.substring(index + 2);
    }
 else {
      string="";
    }
  }
  newStringBuffer.append(string);
  return newStringBuffer.toString();
}

public static String revertNewLines ( 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 ( '\n' ) ; if ( ( index + 2 ) < string . length ( ) ) { string = string . substring ( index + 2 ) ; } 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 ( '\r' ) ; if ( ( index + 2 ) < string . length ( ) ) { string = string . substring ( index + 2 ) ; } else { string = "" ; } } newStringBuffer . append ( string ) ; return newStringBuffer . toString ( ) ; }
reverts \ r and \ n in a string into carriage returns and new lines .
