Example #1
0
        public static RegExReaderData GuessFormat(StreamReader sr)
        {
            string          buffer;
            int             i = 0;
            List <string>   strs;
            string          number = @"\+\-\deE\.";
            RegExReaderData rx     = new RegExReaderData(@"\s*[" + number + @"]+([^" + number + @"]+)[" + number + @"]", new string[] { });


            List <string> guesses = new List <string>();

            while ((strs = rx.GetNextStrings(sr)) != null)
            {
                if (strs.Count > 0)
                {
                    guesses.Add(strs[0]);
                }

                i++;
                if (i > 50)
                {
                    break;
                }
            }

            Dictionary <string, int> frequency = new Dictionary <string, int>();

            foreach (string s in guesses)
            {
                if (!frequency.ContainsKey(s))
                {
                    frequency.Add(s, 0);
                }

                frequency[s]++;
            }

            string mostcommon = ";";
            int    max        = 0;

            foreach (string key in frequency.Keys)
            {
                if (frequency[key] > max)
                {
                    max        = frequency[key];
                    mostcommon = key;
                }
            }

            RegExReaderData reg = new RegExReaderData(mostcommon);

            return(reg);
        }
        List <string> ReadHeader(StreamReader sr)
        {
            List <string> names;
            List <string> strs = RegExReaderData.GetNextStrings(sr);

            if (HasHeader)
            {
                names = strs;
            }
            else
            {
                names = new List <string>();
                for (int i = 0; i < strs.Count; i++)
                {
                    names.Add(i.ToString());
                }
            }

            return(names);
        }