private static String quoteReplacement(final String s) {
    if (s.indexOf('\\') == -1 && s.indexOf('$') == -1) {
      return s;
    }
    final StringBuffer sb = new StringBuffer();
    for (int i = 0; i < s.length(); i++) {
      final char c = s.charAt(i);
      if (c == '\\') {
        sb.append('\\');
        sb.append('\\');
      } else if (c == '$') {
        sb.append('\\');
        sb.append('$');
      } else {
        sb.append(c);
      }
    }
    return sb.toString();
  }
private static String quoteReplacement ( final String s ) { if ( s . indexOf ( '\\' ) == - 1 && s . indexOf ( '$' ) == - 1 ) { return s ; } final StringBuffer sb = new StringBuffer ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { final char c = s . charAt ( i ) ; if ( c == '\\' ) { sb . append ( '\\' ) ; sb . append ( '\\' ) ; } else if ( c == '$' ) { sb . append ( '\\' ) ; sb . append ( '$' ) ; } else { sb . append ( c ) ; } } return sb . toString ( ) ; }
/* for jdk 1.4