예제 #1
0
        static void Main(string[] args)
        {
            // Reality Checks
            if (args.Length != 1)
            {
                Console.WriteLine("1 argument is expected.");
                return;
            }
            if (!File.Exists(args[0]))
            {
                Console.WriteLine($"File '{args[0]}' not found.");
                return;
            }
            WordSearcher searcher = WordSearcher.FromFile(args[0]);

            do
            {
                string input = PromptForSearchWord();
                if (string.IsNullOrWhiteSpace(input))
                {
                    return;
                }
                int nOccur = searcher.GetWordCount(input);
                Console.WriteLine($"The text '{input}' occurs {nOccur} times.");
            } while (true);
        }
예제 #2
0
파일: Program.cs 프로젝트: JohnN4/myfiles
        static void Main(string[] args)
        {
            string document = File.ReadAllText("mobydick.txt");

            WordSearcher searcher = new WordSearcher(document);

            while (PromptForSeachWord(out string searchWord))
            // CountWord(document, searchWord);
            {
                int count = searcher.GetWordCount(searchWord, false);
                Console.WriteLine($"the word {searchWord} was found {count} time(s).");
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("1 argument expected");
                return;
            }
            WordSearcher searcher = WordSearcher.FromFile(args[0]);

            do
            {
                string input = PromptForSearchWord("Please enter text to search for: ");
AskCase:

                string caseSen = PromptForSearchWord("Should this search be case sensitive? y/n ");
                bool cs = false;
                switch (caseSen.ToLower())
                {
                case "y":
                    cs = true;
                    break;

                case "n":
                    cs = false;
                    break;

                default:
                    Console.WriteLine("You must enter Y or N");
                    goto AskCase;
                    break;
                }
                if (string.IsNullOrWhiteSpace(input))
                {
                    return;
                }
                int nOccur = searcher.GetWordCount(input, cs);
                Console.WriteLine($"The text {input} appears {nOccur} times");
            } while (true);
        }