public bool Load(LusuoStream lf, Encoding encoding) { if (null == lf) { return(false); } //if (lf.Length() <= 0) //{ // return false; //} StreamReader sr = new StreamReader(lf.GetStream(), encoding); string strEName = sr.ReadLine(); if (string.IsNullOrEmpty(strEName)) { return(false); } m_strArrEName = strEName.Split(','); if (!NoSame(ref m_strArrEName)) { //Debug.LogError("表头第一行重复!读取失败!" + strEName); return(false); } string strCName = sr.ReadLine(); if (string.IsNullOrEmpty(strCName)) { return(false); } m_strArrCName = strCName.Split(','); if (!NoSame(ref m_strArrCName)) { //Debug.LogError("表头第二行重复!读取失败!"); return(false); } string strType = sr.ReadLine(); if (string.IsNullOrEmpty(strType)) { return(false); } string[] strArrType = strType.Split(','); m_IndexType = new CsvEx.eTypes[strArrType.Length]; for (int ii = 0; ii < strArrType.Length; ii++) { m_IndexType[ii] = String2Type(ref strArrType[ii]); } string strTemp; while (!string.IsNullOrEmpty(strTemp = sr.ReadLine())) { List <string> listString = new List <string>(); string[] strArr = strTemp.Split(','); if (strArr.Length > 0 && IsEmptyOrSpace(strArr[0])) { continue; } for (int i = 0; i < strArr.Length; i++) { listString.Add(strArr[i]); } m_dt.Add(listString); } if (!CheckCSV()) { return(false); } return(true); }
public void Save(LusuoStream lf, Encoding ecoding) { if (null == lf) { return; } StreamWriter sw = new StreamWriter(lf.GetStream(), ecoding); for (int i = 0; i < m_strArrEName.Length; i++) { m_strSaveData += m_strArrEName[i]; if (i < m_strArrEName.Length - 1) { m_strSaveData += ","; } } sw.WriteLine(m_strSaveData); m_strSaveData = ""; for (int i = 0; i < m_strArrCName.Length; i++) { m_strSaveData += m_strArrCName[i]; if (i < m_strArrCName.Length - 1) { m_strSaveData += ","; } } sw.WriteLine(m_strSaveData); m_strSaveData = ""; for (int i = 0; i < m_IndexType.Length; i++) { m_strSaveData += Type2String(m_IndexType[i]); if (i < m_strArrCName.Length - 1) { m_strSaveData += ","; } } sw.WriteLine(m_strSaveData); m_strSaveData = ""; for (int i = 0; i < m_dt.Count; i++) { if (IsEmptyOrSpace(m_dt[i][0])) { continue; } for (int j = 0; j < m_dt[0].Count; j++) { m_strSaveData += m_dt[i][j]; if (j < m_dt[0].Count - 1) { m_strSaveData += ","; } } if (i < m_dt.Count - 1) { sw.WriteLine(m_strSaveData); } else { sw.Write(m_strSaveData); } m_strSaveData = ""; } sw.Close(); }