Esempio n. 1
0
        public override StringTable GetTable()
        {
            StringTable   temp          = SavedTable.GetTable();
            List <string> columntocount = temp.GetColumn(NameColumn);
            StringTable   newtable      = new StringTable();

            newtable.NewColumn(NameColumn);
            newtable.NewColumn("Amount");
            List <string> uniquellabels = new List <string>();
            List <int>    amounts       = new List <int>();

            for (int i = 0; i < columntocount.Count; i++)
            {
                if (uniquellabels.Contains(columntocount[i]))
                {
                    amounts[uniquellabels.IndexOf(columntocount[i])] += 1;
                }
                else
                {
                    uniquellabels.Add(columntocount[i]);
                    amounts.Add(1);
                }
            }
            foreach (string i in uniquellabels)
            {
                newtable.AddValueToColumn(NameColumn, i);
            }
            foreach (int i in amounts)
            {
                newtable.AddValueToColumn("Amount", i.ToString());
            }

            return(newtable);
        }
Esempio n. 2
0
        private void ParseFile(ContentManager content)
        {
            var          filepath = Path.Combine(content.RootDirectory, stringpath);
            Stream       file     = TitleContainer.OpenStream(filepath);
            StreamReader tempo    = new StreamReader(file);


            string thewholething = tempo.ReadToEnd();

            savedtable = new StringTable();
            int           line           = 0;
            int           column         = 0;
            string        fieldToEnter   = "";
            List <string> Columnsbyindex = new List <string>();

            //string currentline = tempo.ReadLine();

            for (int i = 0; i < thewholething.Length; i++)
            {
                if (thewholething[i] != ",".ToCharArray()[0] && thewholething[i] != "\n".ToCharArray()[0] && thewholething[i] != "\r".ToCharArray()[0])
                {
                    fieldToEnter += thewholething[i];
                }
                else
                {
                    if (thewholething[i] == ",".ToCharArray()[0] && thewholething[i + 1] != "\n".ToCharArray()[0])
                    {
                        if (line == 0)
                        {
                            if (fieldToEnter == "")
                            {
                                savedtable.NewColumn("Empty");
                                Columnsbyindex.Add("Empty");
                            }
                            else
                            {
                                savedtable.NewColumn(fieldToEnter);
                                Columnsbyindex.Add(fieldToEnter);
                            }
                        }
                        else
                        {
                            if (column < Columnsbyindex.Count)
                            {
                                savedtable.AddValueToColumn(Columnsbyindex[column], fieldToEnter);
                            }
                        }
                        fieldToEnter = "";
                        column++;
                    }
                    if (thewholething[i] == "\n".ToCharArray()[0] || thewholething[i] == "\r".ToCharArray()[0])
                    {
                        if (line == 0)
                        {
                            savedtable.NewColumn(fieldToEnter);
                            Columnsbyindex.Add(fieldToEnter);
                        }
                        else
                        {
                            if (column < Columnsbyindex.Count)
                            {
                                savedtable.AddValueToColumn(Columnsbyindex[column], fieldToEnter);
                            }
                        }
                        fieldToEnter = "";
                        column       = 0;
                        line++;
                    }
                }
            }


            savedtable.RemoveColumn("Empty");
            tempo.Close();
        }