Esempio n. 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);
        }
Esempio n. 2
0
 private void TextArea_Drop(object sender, DragEventArgs e)
 {
     if (e.Data.GetData(DataFormats.FileDrop) is string[] paths && paths.Length > 0)
     {
         _wordSearcher = WordSearcher.FromFile(paths[0]);
         paragraph.Inlines.Clear();
         paragraph.Inlines.Add(new Run {
             Text = _wordSearcher.Document
         });
         prompt.Visibility = Visibility.Collapsed;
     }
 }
Esempio n. 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);
        }