Need some help for creating a File and String search engine.
The program needs to get the user to enter the name of the file then enter the name of a search string the print a search result file, store it then ask the user if they want another selection.
This is what i have so far:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
public class SwitchTest
{
private const int tabSize = 4;
private const string usageText = "Usage: INSERTTABS inputfile.txt outputfile.txt";
public static void Main(string[] args)
{
string userinput;
Console.WriteLine("Please enter the file to be searched");
userinput = Console.ReadLine();
using (StreamReader reader = new StreamReader("test.txt"))
{
//Read the file into a stringbuilder
StringBuilder sb = new StringBuilder();
sb.Append(reader.ReadToEnd());
Console.ReadLine();
}
{
StreamWriter writer = null;
if (args.Length < 2)
{
Console.WriteLine(usageText);
return;
}
try
{
// Attempt to open output file.
writer = new StreamWriter(args[1]);
// Redirect standard output from the console to the output file.
Console.SetOut(writer);
// Redirect standard input from the console to the input file.
Console.SetIn(new StreamReader(args[0]));
}
catch (IOException e)
{
TextWriter errorWriter = Console.Error;
errorWriter.WriteLine(e.Message);
errorWriter.WriteLine(usageText);
return;
}
writer.Close();
// Recover the standard output stream so that a
// completion message can be displayed.
StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
standardOutput.AutoFlush = true;
Console.SetOut(standardOutput);
Console.WriteLine("COMPLETE!", args[0]);
return;
}
}
}
I am rubbish at programming so keep it simple with the terminology xD
I don’t really know what you want, but if you want to search a file for all occurances of a string, and want to return the position (line and column) then this might help: