code: public static String quote(String s, String delim)
      {
          if (s==null)
              return null;
          if (s.length()==0)
              return "\"\"";
  
          
          for (int i=0;i<s.length();i++)
          {
              char c = s.charAt(i);
              if (c=='"' ||
                  c=='\\' ||
                  c=='\'' ||
                  delim.indexOf(c)>=0)
              {
                  StringBuffer b=new StringBuffer(s.length()+8);
                  quote(b,s);
                  return b.toString();
              }
          }
          
          return s;
      }
docs: Quote a string.
  The string is quoted only if quoting is required due to
  embeded delimiters, quote characters or the
  empty string.
  @param s The string to quote.
  @return quoted string