public static String backQuoteChars(String string){
  int index;
  StringBuffer newStringBuffer;
  char charsFind[]={'\\','\'','\t','\n','\r','"','%','\u001E'};
  String charsReplace[]={"\\\\","\\'","\\t","\\n","\\r","\\\"","\\%","\\u001E"};
  for (int i=0; i < charsFind.length; i++) {
    if (string.indexOf(charsFind[i]) != -1) {
      newStringBuffer=new StringBuffer();
      while ((index=string.indexOf(charsFind[i])) != -1) {
        if (index > 0) {
          newStringBuffer.append(string.substring(0,index));
        }
        newStringBuffer.append(charsReplace[i]);
        if ((index + 1) < string.length()) {
          string=string.substring(index + 1);
        }
 else {
          string="";
        }
      }
      newStringBuffer.append(string);
      string=newStringBuffer.toString();
    }
  }
  return string;
}

public static String backQuoteChars ( String string ) { int index ; StringBuffer newStringBuffer ; char charsFind [ ] = { '\\' , '\'' , '\t' , '\n' , '\r' , '"' , '%' , '' } ; String charsReplace [ ] = { "\\\\" , "\\'" , "\\t" , "\\n" , "\\r" , "\\\"" , "\\%" , "\\u001E" } ; for ( int i = 0 ; i < charsFind . length ; i ++ ) { if ( string . indexOf ( charsFind [ i ] ) != - 1 ) { newStringBuffer = new StringBuffer ( ) ; while ( ( index = string . indexOf ( charsFind [ i ] ) ) != - 1 ) { if ( index > 0 ) { newStringBuffer . append ( string . substring ( 0 , index ) ) ; } newStringBuffer . append ( charsReplace [ i ] ) ; if ( ( index + 1 ) < string . length ( ) ) { string = string . substring ( index + 1 ) ; } else { string = "" ; } } newStringBuffer . append ( string ) ; string = newStringBuffer . toString ( ) ; } } return string ; }
converts carriage returns and new lines in a string into \ r and \ n . backquotes the following characters : ` " \ \ t and %
