Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.IO;
- class SearchingProgram
- {
- public static void Main(string[] args)
- {
- menu();
- // shows menu
- }
- public static void menu()
- {
- string selection = "0";
- // holds the user's selection - default is 0 to keep menu looping
- while (selection != "9")
- // loops unless 9 is pressed
- {
- Console.Clear();
- // clears screen - good for clearing clutter after the user has performed an action
- TitleLine(" Search Program");
- SpacingLine();
- Console.WriteLine("[1] Select File To Be Searched");
- Console.WriteLine("[2] Enter Search Term");
- Console.WriteLine("[3] Search Statistics");
- Console.WriteLine("[4] Display and Save Results");
- Console.WriteLine("[5] Reset All");
- Console.WriteLine("[9] Exit");
- SpacingLine();
- Console.Write("Please make a selection: ");
- selection = Console.ReadLine();
- // user's selection is recorded
- SpacingLine();
- switch (selection)
- {
- case "1":
- Console.Clear();
- TitleLine("Select File To Be Searched");
- SpacingLine();
- string importedContents = selectFile();
- break;
- case "2":
- Console.Clear();
- TitleLine("Enter Search Term");
- SpacingLine();
- string searchTermInput = searchTerm();
- break;
- case "3":
- Console.Clear();
- TitleLine("Search Statistics");
- SpacingLine();
- statistics();
- break;
- case "4":
- Console.Clear();
- TitleLine("Display and Save Results");
- SpacingLine();
- results(importedContents, searchTermInput);
- break;
- case "5":
- Console.Clear();
- TitleLine("Reset All");
- SpacingLine();
- break;
- case "9":
- break;
- } // ends switch
- } // ends while loop
- }
- public static string selectFile()
- {
- string selectedFile;
- string importedContents;
- Console.WriteLine("Please enter the filename and extension of the file you want to search (e.g: anglia.txt)");
- SpacingLine();
- selectedFile = Console.ReadLine();
- using (StreamReader rdr = File.OpenText("C:/Users/Billy/Documents/Search/Text Search/to_be_searched/"+selectedFile))
- {
- importedContents = rdr.ReadToEnd();
- // reads text file and strores in importedContents variable
- }
- return importedContents;
- }
- public static string searchTerm()
- {
- string searchTermInput;
- Console.WriteLine("Please insert your search term: ");
- SpacingLine();
- searchTermInput = Console.ReadLine();
- return searchTermInput;
- }
- public static void statistics()
- {
- }
- public static void results(string textToSearch, string whatToSearch)
- {
- if (textToSearch.Contains(whatToSearch))
- {
- Console.WriteLine("FOUND!!");
- Console.ReadLine();
- }
- else
- {
- Console.WriteLine("NOT FOUND!!");
- Console.ReadLine();
- }
- }
- public static void SpacingLine()
- {
- Console.WriteLine();
- }
- // formatting method
- public static void TitleLine(string s)
- {
- Console.WriteLine("==============================");
- Console.WriteLine(s);
- Console.WriteLine("==============================");
- }
- // formatting method
- public static void EnterToContinue()
- {
- SpacingLine();
- Console.WriteLine("==============================");
- Console.WriteLine("Push 'Enter' To Continue");
- Console.WriteLine("==============================");
- Console.ReadLine();
- }
- // formatting method
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement