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,m_MaxDecimalPlaces);
    }
    if (m_FieldSeparator.length() == 1 && (field.indexOf(m_FieldSeparator) > -1) && !field.startsWith("'") && !field.endsWith("'")) {
      field="'" + field + "'";
    }
    result.append(field);
  }
  return result.toString();
}

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 , m_MaxDecimalPlaces ) ; } if ( m_FieldSeparator . length ( ) == 1 && ( field . indexOf ( m_FieldSeparator ) > - 1 ) && ! field . startsWith ( "'" ) && ! field . endsWith ( "'" ) ) { field = "'" + field + "'" ; } result . append ( field ) ; } return result . toString ( ) ; }
turns an instance into a string . takes care of sparse instances as well .
