code: public static String escapeChars(String str, String chars) {
          StringBuilder sb = new StringBuilder();
  
          for (int i = 0; i < str.length(); i++) {
              char c = str.charAt(i);
  
              if (chars.indexOf(c) >= 0) {
                  sb.append('\\');
              }
  
              sb.append(c);
          }
  
          return sb.toString();
      }
docs: Escapes the characters from {@code chars} in the {@code str} parameter.
  
  @param str
  the string to escape
  @param chars
  the characters to escape
  @return the escaped string