当前位置: 首页>>代码示例>>C#>>正文


C# CsvReader.ParseRecord方法代码示例

本文整理汇总了C#中CsvReader.ParseRecord方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.ParseRecord方法的具体用法?C# CsvReader.ParseRecord怎么用?C# CsvReader.ParseRecord使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsvReader的用法示例。


在下文中一共展示了CsvReader.ParseRecord方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExtractData

        private static Dictionary<string, Dictionary<string, double>> ExtractData(FileInfo f)
        {
            List<string> headers = new List<string>();
            List<string> data = new List<string>();
            Dictionary<string, Dictionary<string, double>> output = new Dictionary<string, Dictionary<string, double>>();

            using (CsvReader r = new CsvReader(f.FullName))
            {
                data = r.ParseRecord();

                for (int i = 1; i < data.Count - 1; i++)
                {
                    headers.Add(data[i]);
                }

                while (!r.EndOfStream)
                {
                    data = r.ParseRecord();

                    output.Add(data[0], new Dictionary<string, double>());

                    for (int i = 1; i < headers.Count; i++)
                    {
                        output[data[0]].Add(headers[i], double.Parse(data[i]));
                    }
                }
            }

            return output;
        }
开发者ID:TonyBarnett,项目名称:Research,代码行数:30,代码来源:Program.cs

示例2: GetData

        private static List<List<string>> GetData(string file)
        {
            List<List<string>> ret = new List<List<string>>();
            using (CsvReader r = new CsvReader(file))
            {
                while (!r.EndOfStream)
                {
                    List<string> data = r.ParseRecord();
                    double result = new double();
                    ret.Add(data.Where(x => x != "" && !double.TryParse(x, out result)).ToList<string>());

                    _Totals.Add(result);
                }
            }

            return ret;
        }
开发者ID:TonyBarnett,项目名称:Research,代码行数:17,代码来源:Program.cs

示例3: WriteIntensities

        private static void WriteIntensities(int year)
        {
            List<List<object>> o = new List<List<object>>();
            using (CsvReader r = new CsvReader(string.Format(@"E:\Dropbox\matlabFiles\VariableRecords\IOModel{0}.csv", year)))
            {
                int i = 0;
                while (!r.EndOfStream)
                {
                    o.Add(new List<object>());
                    List<string> thing = r.ParseRecord();
                    o[i].Add(year);
                    foreach (string t in thing)
                    {
                        o[i].Add(t);
                    }
                    i++;
                }
            }

            DB.LoadToTable("Intensity", o);
        }
开发者ID:TonyBarnett,项目名称:Research,代码行数:21,代码来源:Program.cs

示例4: CreateModel

        private static void CreateModel(object year)
        {
            Dictionary<string, Dictionary<string, double>> ASic = new Dictionary<string, Dictionary<string, double>>();
            Dictionary<string, Dictionary<string, string>> description = new Dictionary<string, Dictionary<string, string>>();

            List<string> sicNasty = new List<string>();
            List<string> headers = new List<string>();
            using (CsvReader r = new CsvReader(string.Format(@"E:\Dropbox\IO Model source data\A{0}.csv", year)))
            {
                foreach (string s in r.ParseRecord())
                {
                    if (s.Trim() != "")
                    {
                        headers.Add(s.Trim());
                        ASic.Add(s.Trim(), new Dictionary<string, double>());
                    }
                }

                r.ParseRecord();

                description.Add("A", new Dictionary<string, string>());
                while (!r.EndOfStream)
                {
                    List<string> records = new List<string>();
                    foreach (string s in r.ParseRecord())
                    {
                        records.Add(s.Trim());
                    }

                    sicNasty.Add(records[0].Trim());

                    description["A"].Add(records[0], records[1]);

                    for (int i = 2; i < records.Count - 1; i++)
                    {
                        string thing = headers[i - 2];
                        thing = records[i];
                        thing = records[0];
                        Dictionary<string, double> t = ASic[thing];
                        // We want the proportion of each element in each row divided by the row total.
                        ASic[records[0]].Add(headers[i - 2], double.Parse(records[i] == "" ? "0" : records[i]));
                    }
                }
            }

            List<List<object>> a = new List<List<object>>();

            int j = 0;
            foreach (string s in ASic.Keys)
            {
                foreach (string v in ASic[s].Keys)
                {
                    a.Add(new List<object>());
                    a[j].Add(year);
                    a[j].Add(s);
                    a[j].Add(v);
                    a[j++].Add(ASic[s][v]);
                }
            }

            List<List<object>> aHeaders = new List<List<object>>();
            j = 0;

            foreach (List<object> o in a)
            {
                if (!ContainsObject(aHeaders, o[0]))
                {
                    aHeaders.Add(new List<object>());
                    aHeaders[j++].Add(o[0]);
                }
            }

            List<List<object>> b = new List<List<object>>();

            using (CsvReader r = new CsvReader(string.Format(@"E:\Dropbox\IO Model source data\B{0}.csv", year)))
            {
                int k = 0;
                r.ParseRecord();
                description.Add("B", new Dictionary<string, string>());
                while (!r.EndOfStream)
                {
                    List<string> records = r.ParseRecord();
                    sicNasty.Add(records[0]);
                    b.Add(new List<object>());
                    b[k].Add(year);
                    b[k].Add(records[0].Replace("\r", ""));
                    b[k++].Add(records[2].Replace("\r", ""));
                    if (!description["A"].ContainsKey(records[0]))
                    {
                        description["B"].Add(records[0], records[1]);
                    }
                    if (!headers.Contains(records[0]))
                    {
                        headers.Add(records[0]);
                    }
                }
            }

            List<List<object>> desc = new List<List<object>>();

//.........这里部分代码省略.........
开发者ID:TonyBarnett,项目名称:Research,代码行数:101,代码来源:Program.cs

示例5: GetClasSystem

        private static Dictionary<string, string> GetClasSystem(FileInfo f, int sysId, int description)
        {
            Dictionary<string, string> data = new Dictionary<string, string>();

            using (CsvReader r = new CsvReader(f.FullName))
            {
                List<string> record = new List<string>();
                // Skip header row.
                if (string.IsNullOrEmpty(_Sys0))
                {
                    _Sys0 = r.ParseRecord()[description];
                }
                else
                {
                    _Sys1 = r.ParseRecord()[description];
                }

                while (!r.EndOfStream)
                {
                    record = r.ParseRecord();
                    if (!string.IsNullOrEmpty(record[description]))
                    {
                        data.Add(record[sysId], record[description]);
                    }
                }
            }

            return data;
        }
开发者ID:TonyBarnett,项目名称:Research,代码行数:29,代码来源:Program.cs


注:本文中的CsvReader.ParseRecord方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。