Example #1
0
    public bool LoadCsv(string fileName, string path)
    {
        TextAsset csvfile = Resources.Load(path, typeof(TextAsset)) as TextAsset;
        //Debug.Log(csvfile.text);
        CsvData data = new CsvData();

        data.Init();
        data.SetFileName(fileName);

        string strbuff = "";

        //按行分割字符串
        string[] list_file = SplitString(csvfile.text.Trim(), '\r');
        string[] keys      = SplitString(list_file[0].Trim(), ',');

        for (int i = 1; i < list_file.Length; i++)
        {
            Dictionary <string, string> dist_file = new Dictionary <string, string>();
            dist_file.Clear();
            string[] datas = SplitString(list_file[i], ',');
            for (int j = 0; j < datas.Length; j++)
            {
                //Debug.Log(keys[j]+"---"+datas[j].Trim());

                dist_file.Add(keys[j], datas[j].Trim());
            }
            //Debug.Log(i);
            data.PushData(i.ToString(), dist_file);
            //Debug.Log(i);
        }
        //Debug.Log(fileName);
        m_AllDatas.Add(fileName, data);

        return(true);
    }
Example #2
0
 public TestCSVData()
 {
     data = new CsvData();
     data.Init(filePath);
 }