java: 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();}
C#: public static string quoteReplacement(string s){java.lang.StringBuilder result = new java.lang.StringBuilder(s.Length);{for (int i = 0; i < s.Length; i++){char c = s[i];if (c == '\\' || c == '$'){result.append('\\');}result.append(c);}}return result.ToString();}