cdm/src/main/java/ucar/nc2/util/EscapeStrings.java
static public String backslashEscapeCDMString(String s, String toescape)
    {
      if(toescape == null || toescape.length() == 0) return s;
      if(s == null || s.length() == 0) 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();
    }
static public String backslashEscapeCDMString(String s, String toescape)
    {
      if(toescape == null || toescape.length() == 0) return s;
      if(s == null || s.length() == 0) 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();
    }
Given a CDM string, insert backslashes
before <toescape> characters.