class EscapeStrings {

  public static String backslashEscapeCDMString(String s, String toescape) {
    if (toescape == null || toescape.isEmpty()) {
      return s;
    }
    if (s == null || s.isEmpty()) {
      return s;
    }
    StringBuilder buf = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
      int c = s.charAt(i);
      if (toescape.indexOf(c) >= 0) {
        buf.append('\\');
      }
      buf.append((char) c);
    }
    return buf.toString();
  }

}