示例#1
0
        static void Main(string[] args)
        {
            while (!exit)
            {
                MainMenu();

                string choiceString = Console.ReadLine();
                int    intChoice;
                string txtFile;

                //Verifies the user input to make sure that they are inputing a number integer option.3
                while (!int.TryParse(choiceString, out intChoice))
                {
                    Console.Clear();
                    MainMenu();
                    Console.WriteLine("Please enter a valid number.");
                    choiceString = Console.ReadLine();
                }

                switch (intChoice)
                {
                case 1:
                    //Retrieves the text file input from the ReadFile method and puts it in the txtFile string.
                    txtFile = ReadFile();

                    if (txtFile != null)
                    {
                        Console.Clear();
                        Console.WriteLine(txtFile);
                        Console.WriteLine("The text file has {0} words.", StringOperators.WordCount(txtFile));
                        Console.WriteLine("The text file has {0} vowels", StringOperators.CharCount(txtFile, true));
                        Console.WriteLine("The text file has a string value of {0}", StringOperators.CharCount(txtFile, false));
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadKey();
                    }
                    break;

                case 2:
                    //Creates an empty text file in user designated path and validates the path
                    CreateFile();
                    break;

                case 3:
                    //Exits the program
                    Console.Clear();
                    exit = true;
                    break;

                default:
                    //By default, will return to the beginingof the loop, most likely due to incorrect option being selected.
                    Console.Clear();
                    Console.WriteLine("Please enter a valid choice of 1, 2, or 3.");
                    Console.ReadKey();
                    break;
                }
            }
        }