protected String instanceToString(Instance inst) {
    StringBuffer	result;
    Instance 		outInst;
    int			i;
    String		field;

    result = new StringBuffer();
    
    if (inst instanceof SparseInstance) {
      outInst = new DenseInstance(inst.weight(), inst.toDoubleArray());
      outInst.setDataset(inst.dataset());
    }
    else {
      outInst = inst;
    }
    
    for (i = 0; i < outInst.numAttributes(); i++) {
      if (i > 0)
	result.append(m_FieldSeparator);
      
      if (outInst.isMissing(i))
	field = m_MissingValue;
      else
	field = outInst.toString(i);
      
      // make sure that custom field separators, like ";" get quoted correctly
      // as well
      if ((field.indexOf(m_FieldSeparator) > -1) && !field.startsWith("'") && !field.endsWith("'"))
	field = "'" + field + "'";
      
      result.append(field);
    }

    return result.toString();
  }