public static String quoteReplacement(String s){
  StringBuilder result=new StringBuilder(s.length());
  for (int i=0; i < s.length(); i++) {
    char c=s.charAt(i);
    if (c == '\\' || c == '$') {
      result.append('\\');
    }
    result.append(c);
  }
  return result.toString();
}

public static String quoteReplacement ( String s ) { StringBuilder result = new StringBuilder ( s . length ( ) ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( c == '\\' || c == '$' ) { result . append ( '\\' ) ; } result . append ( c ) ; } return result . toString ( ) ; }
returns a replacement string for the given one that has all backslashes and dollar signs escaped .
