コード例 #1
0
        /// <summary>
        /// Analysis *.txt file
        /// </summary>
        private static void AnalysisFile(string pathFile)
        {
            // guard operator
            if (Path.GetExtension(pathFile) != ".txt")
            {
                return;
            }

            // message
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("\nInput is *.txt file.\n");
            Console.ResetColor();
            try
            {
                using (FileStream stream = new FileStream(pathFile,
                                                          FileMode.Open, FileAccess.Read, FileShare.None))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        // read to end
                        string data = reader.ReadToEnd();
                        // analysis the data
                        //TextAnalysis.GetGroupOfWords0(data).ToPresent();
                        // or
                        TextAnalysis.GetGroupOfWords1(data).ToPresent();
                    }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // join unicode
            Console.OutputEncoding = Encoding.Unicode;

            string testStr = "The “C# Professional” course includes the topics " +
                             "I discuss in my CLR via C# book and teaches how the CLR works " +
                             "thereby showing you how to develop applications and reusable " +
                             "components for the .NET Framework.";

            // testing with timer
#if test
            Stopwatch timer  = new Stopwatch();
            double[]  result = new double[2];
#endif

            #region Variant 1
#if false
#if test
            timer.Start();
#endif
            // analysis of string and show result
            var v1 = TextAnalysis.GetGroupOfWords0(testStr);
#if test
            timer.Stop();
            result[0] = timer.Elapsed.TotalSeconds;
#endif
            Console.WriteLine();
            v1.ToPresent();
#endif
            #endregion

            #region Variant 2
#if false
            // create file for testing
            // CreateTestFile();

            // when, the user want to fall the *.txt file
            if (args.Length > 0)
            {
                AnalysisFile(args[0]);
            }
#endif
            #endregion

            #region Variant 3
#if true
#if test
            timer.Restart();
#endif
            // analysis of string and show result
            var v3 = TextAnalysis.GetGroupOfWords1(testStr);//.ToPresent();
#if test
            timer.Stop();
            result[1] = timer.Elapsed.TotalSeconds;
#endif
            Console.WriteLine();
            v3.ToPresent();
#if test
            Console.WriteLine();
            Console.WriteLine($"Variant 1: " + result[0]);
            Console.WriteLine($"Variant 3: " + result[1]);
#endif
#endif
            #endregion

            // delay
            Console.ReadKey(true);
        }