Advertisement
steverobinson

debuggung client

Feb 6th, 2011
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5. using System.IO;
  6.  
  7. class SearchingProgram
  8. {
  9.     public static void Main(string[] args)
  10.     {
  11.         menu();
  12.         // shows menu
  13.     }
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.     public static void menu()
  21.     {
  22.  
  23.         string selection = "0";
  24.         // holds the user's selection - default is 0 to keep menu looping
  25.  
  26.         while (selection != "9")
  27.         // loops unless 9 is pressed
  28.         {
  29.             Console.Clear();
  30.  
  31.             // clears screen - good for clearing clutter after the user has performed an action
  32.             TitleLine("       Search Program");
  33.             SpacingLine();
  34.  
  35.             Console.WriteLine("[1] Select File To Be Searched");
  36.             Console.WriteLine("[2] Enter Search Term");
  37.             Console.WriteLine("[3] Search Statistics");
  38.             Console.WriteLine("[4] Display and Save Results");
  39.             Console.WriteLine("[5] Reset All");
  40.             Console.WriteLine("[9] Exit");
  41.  
  42.             SpacingLine();
  43.  
  44.             Console.Write("Please make a selection: ");
  45.  
  46.             selection = Console.ReadLine();
  47.             // user's selection is recorded
  48.  
  49.             SpacingLine();
  50.  
  51.             switch (selection)
  52.             {
  53.                 case "1":
  54.                     Console.Clear();
  55.                     TitleLine("Select File To Be Searched");
  56.                     SpacingLine();
  57.                     string importedContents = selectFile();
  58.                     break;
  59.                 case "2":
  60.                     Console.Clear();
  61.                     TitleLine("Enter Search Term");
  62.                     SpacingLine();
  63.                     string searchTermInput = searchTerm();
  64.                     break;
  65.                 case "3":
  66.                     Console.Clear();
  67.                     TitleLine("Search Statistics");
  68.                     SpacingLine();
  69.                     statistics();
  70.                     break;
  71.                 case "4":
  72.                     Console.Clear();
  73.                     TitleLine("Display and Save Results");
  74.                     SpacingLine();
  75.                     results(importedContents, searchTermInput);
  76.                     break;
  77.                 case "5":
  78.                     Console.Clear();
  79.                     TitleLine("Reset All");
  80.                     SpacingLine();
  81.  
  82.                     break;
  83.                 case "9":
  84.                     break;
  85.             } // ends switch
  86.         } // ends while loop
  87.     }
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.      public static string selectFile()
  95.     {
  96.         string selectedFile;
  97.         string importedContents;
  98.  
  99.         Console.WriteLine("Please enter the filename and extension of the file you want to search (e.g: anglia.txt)");
  100.         SpacingLine();
  101.         selectedFile = Console.ReadLine();
  102.         using (StreamReader rdr = File.OpenText("C:/Users/Billy/Documents/Search/Text Search/to_be_searched/"+selectedFile))
  103.         {
  104.             importedContents = rdr.ReadToEnd();
  105.             // reads text file and strores in importedContents variable
  106.         }
  107.  
  108.         return importedContents;
  109.     }
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.      public static string searchTerm()
  117.      {
  118.          string searchTermInput;
  119.  
  120.          Console.WriteLine("Please insert your search term:  ");
  121.          SpacingLine();
  122.          searchTermInput = Console.ReadLine();
  123.  
  124.          return searchTermInput;
  125.      }
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.      public static void statistics()
  133.      {
  134.  
  135.      }
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.      public static void results(string textToSearch, string whatToSearch)
  143.      {
  144.  
  145.  
  146.          if (textToSearch.Contains(whatToSearch))
  147.          {
  148.              Console.WriteLine("FOUND!!");
  149.              Console.ReadLine();
  150.          }
  151.          else
  152.          {
  153.              Console.WriteLine("NOT FOUND!!");
  154.              Console.ReadLine();
  155.          }
  156.      }
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.     public static void SpacingLine()
  164.     {
  165.         Console.WriteLine();
  166.     }
  167.     // formatting method
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.     public static void TitleLine(string s)
  175.     {
  176.         Console.WriteLine("==============================");
  177.         Console.WriteLine(s);
  178.         Console.WriteLine("==============================");
  179.     }
  180.     // formatting method
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.     public static void EnterToContinue()
  188.     {
  189.         SpacingLine();
  190.         Console.WriteLine("==============================");
  191.         Console.WriteLine("Push 'Enter' To Continue");
  192.         Console.WriteLine("==============================");
  193.         Console.ReadLine();
  194.     }
  195.     // formatting method
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement