Does anyone can tell me where and how exactly to specify path input in following code for pattern(keyword) which is in a file C:\\"pattern.txt" and text (to be searched through) which is in a file C:\\"text.txt" to make it work.
I tried couple of things but application will always return:
this message: "Usage: BoyerMoore_Demo <filename> <texttofind>"
Thank you very much in advance.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Diagnostics;
namespace StringMatch
{
class BoyerMoore_Demo
{
public static void Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("Usage: BoyerMoore_Demo <filename> <texttofind>");
return;
}
using (TextReader rdr = new StreamReader(args[0]))
{
string text = rdr.ReadToEnd();
string pattern = args[1];
Console.WriteLine("Finding all occurrences of {0} in {1} ({2} characters in length)", pattern, args[0], text.Length);
BoyerMoore bm = new BoyerMoore(pattern);
// make sure everything is JIT'd
foreach (int index in bm.BCLMatch(text))
;
foreach (int index in bm.HorspoolMatch(text))
;
foreach (int index in bm.BoyerMooreMatch(text))
;
foreach (int index in bm.TurboBoyerMooreMatch(text))
;
foreach (int index in bm.ApostolicoGiancarloMatch(text))
;
// measure the algorithms
Stopwatch sw = new Stopwatch();
int matches;
sw.Reset();
sw.Start();
matches = 0;
foreach (int index in bm.BCLMatch(text))
matches++;
sw.Stop();
Console.WriteLine("String.indexOf found {0} matches in {1} seconds", matches, sw.Elapsed.TotalSeconds);
sw.Reset();
sw.Start();
matches = 0;
foreach (int index in bm.HorspoolMatch(text))
matches++;
sw.Stop();
Console.WriteLine("Horspool found {0} matches in {1} seconds", matches, sw.Elapsed.TotalSeconds);
sw.Reset();
sw.Start();
matches = 0;
foreach (int index in bm.BoyerMooreMatch(text))
matches++;
sw.Stop();
Console.WriteLine("Boyer-Moore found {0} matches in {1} seconds", matches, sw.Elapsed.TotalSeconds);
sw.Reset();
sw.Start();
matches = 0;
foreach (int index in bm.TurboBoyerMooreMatch(text))
matches++;
sw.Stop();
Console.WriteLine("Turbo Boyer-Moore found {0} matches in {1} seconds", matches, sw.Elapsed.TotalSeconds);
sw.Reset();
sw.Start();
matches = 0;
foreach (int index in bm.ApostolicoGiancarloMatch(text))
matches++;
sw.Stop();
Console.WriteLine("Apostolico-GiancarloMatch found {0} matches in {1} seconds", matches, sw.Elapsed.TotalSeconds);
}
}
}
}