예제 #1
0
        static void Main(string[] args)
        {
            ArrayList text1 = new ArrayList();
            ArrayList text2 = new ArrayList();
            ArrayList text3 = new ArrayList();
            ArrayList text4 = new ArrayList();
            ArrayList text5 = new ArrayList();
            ArrayList text6 = new ArrayList();
            ArrayList text7 = new ArrayList();
            ArrayList text8 = new ArrayList();
            ArrayList text9 = new ArrayList();
            ArrayList text10 = new ArrayList();
            ArrayList text11 = new ArrayList();
            ArrayList text12 = new ArrayList();
            ArrayList[] texts = new ArrayList[] { text1, text2, text3, text4, text5, text6, text7, text8, text9, text10, text11, text12 };

            //StringBuilder line = new StringBuilder("",256);

            string line1,line2,line3,line4,line5,line6,line7,line8,line9,line10,line11,line12;

            #region filePaths
                line1 = "sports1.txt";
                line2 = "sports2.txt";
                line3 = "sports3.txt";
                line4 = "sports4.txt";
                line5 = "sports5.txt";
                line6 = "sports6.txt";
                line7 = "politics1.txt";
                line8 = "politics2.txt";
                line9 = "poliics3.txt";
                line10 = "politics4.txt";
                line11 = "politics5.txt";
                line12 = "politics6.txt";
            #endregion

            string[] filePaths = new string[] { line1,line2,line3,line4,line5,line6,line7,line8,line9,line10,line11,line12};

                AddWords(ref text1, line1);
                AddWords(ref text2, line2);
                AddWords(ref text3, line3);
                AddWords(ref text4, line4);
                AddWords(ref text5, line5);
                SortedList<string, int> sportsWords = new SortedList<string, int>();
                for (int i = 0; i < 5; i++)
                {
                    String[] text = (String[])texts[i].ToArray(typeof(string));
                    for (int j = 0; j < text.Length; j++)
                    {
                        if (sportsWords.ContainsKey(text[j]))
                        {
                            int indexOfKey = sportsWords.IndexOfKey(text[j]);
                            int valueOfKey;
                            sportsWords.TryGetValue(text[j], out valueOfKey);
                            valueOfKey++;
                            sportsWords.Remove(text[j]);
                            sportsWords.Add(text[j], valueOfKey);

                        }
                        else
                        {
                            sportsWords.Add(text[j], 1);
                        }
                    }
                }
                foreach (var word in sportsWords)
                {
                    Console.WriteLine(word.Key + " " + word.Value);
                }
                //foreach(var item in text1)
                //{
                //    Console.WriteLine(item);
                //}
                //foreach (var item in text2)
                //{
                //    Console.WriteLine(item);
                //}
                //foreach (var item in text3)
                //{
                //    Console.WriteLine(item);
                //}
                //foreach (var item in text4)
                //{
                //    Console.WriteLine(item);
                //}
                //foreach (var item in text5)
                //{
                //    Console.WriteLine(item);
                //}
                Console.WriteLine(text1.Count+text2.Count+text3.Count+text4.Count+text5.Count);
            Console.ReadLine();
        }
예제 #2
0
        private void Select(string query, bool flag)
        {
            m_dbConnection = new SQLiteConnection(ConnectString);
            m_dbConnection.Open();
            SQLiteCommand command = new SQLiteCommand(query, m_dbConnection);
            SQLiteDataReader reader = command.ExecuteReader();
            SortedList<String, int[]> sl = new SortedList<String, int[]>();

            /*
             * As the input we have strings formatted like "string year, string month, int sum"
             * So we'd parse this data and push it into sorted list named sl to output correctly.
             */
            while (reader.Read())
            {
                int year = 0;
                int month = 0;
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    Console.Write(reader.GetValue(i) + "   ");

                    var tmp = reader.GetValue(i);

                    if (tmp.GetType() == typeof(System.String))  //if we have "string - type" variable
                    {
                        int temp = Convert.ToInt32(reader.GetValue(i));    //convert reader string value to int
                        if (temp / 100 != 0)
                        {
                            //memorise year
                            year = temp;
                            //add new year into list and create array for 12 months this year
                            sl.Add(tmp.ToString(), new int[13]);
                        }
                        else
                        {
                            //memorise month
                            month = temp;
                        }
                    }
                    else
                    {
                        int temp = Convert.ToInt32(reader.GetValue(i));
                        int[] value;
                        //get values (array of months and sums)
                        sl.TryGetValue(year.ToString(), out value);
                        value[month] = temp;
                    }
                }
            }
            //close the connection with DB
            m_dbConnection.Close();

            //output
            Console.WriteLine(" Year/  January   February   March   April   May   June   July   August   September   October   November   December");
            foreach (KeyValuePair<string, int[]> pair in sl)
            {
                Console.Write(pair.Key + "   ");
                for (int i = 1; i <= 12; i++)
                {
                    Console.Write("   " + pair.Value[i]);
                }
                Console.WriteLine();
            }
        }
예제 #3
0
 /// <summary>
 /// Parses the specified query string and returns a sorted list containing the arguments found in the specified query string.  Can also be used to parse the POST request body if the mimetype is "application/x-www-form-urlencoded".
 /// </summary>
 /// <param name="queryString"></param>
 /// <param name="requireQuestionMark"></param>
 /// <returns></returns>
 private static SortedList<string, string> ParseQueryStringArguments(string queryString, bool requireQuestionMark = true, bool preserveKeyCharacterCase = false)
 {
     SortedList<string, string> arguments = new SortedList<string, string>();
     int idx = queryString.IndexOf('?');
     if (idx > -1)
         queryString = queryString.Substring(idx + 1);
     else if (requireQuestionMark)
         return arguments;
     idx = queryString.LastIndexOf('#');
     string hash = null;
     if (idx > -1)
     {
         hash = queryString.Substring(idx + 1);
         queryString = queryString.Remove(idx);
     }
     string[] parts = queryString.Split(new char[] { '&' });
     for (int i = 0; i < parts.Length; i++)
     {
         string[] argument = parts[i].Split(new char[] { '=' });
         if (argument.Length == 2)
         {
             string key = Uri.UnescapeDataString(argument[0]);
             if (!preserveKeyCharacterCase)
                 key = key.ToLower();
             string existingValue;
             if (arguments.TryGetValue(key, out existingValue))
                 arguments[key] += "," + Uri.UnescapeDataString(argument[1]);
             else
                 arguments[key] = Uri.UnescapeDataString(argument[1]);
         }
     }
     if (hash != null)
         arguments["#"] = hash;
     return arguments;
 }