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);
      }
    }
  }
}

This can only mean one thing: args.Length(line 13) is less than 2.
You can test this againby changing the string to "hello world" in the WriteLine that follows.

In here:

using (TextReader rdr = new StreamReader(@"C:\"text.txt"))
{
     //code in here
}

This can only mean one thing: args.Length(line 13) is less than 2.
You can test this againby changing the string to "hello world" in the WriteLine that follows.

I know, this is because I didn't declare args properly or not in correct place ( just to make clear- in presented code they are not declared at all)...but it must be something simple.

I tried for example:
args[0] = C:\\"text.txt"
args[1] = C:\\"pattern.txt"

but this is probably not a way how doing it....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.