コード例 #1
0
        public static void Test()
        {
            Console.WriteLine("Enter haystack:");
            string haystack = Console.ReadLine();

            Console.WriteLine();

            Console.WriteLine("Enter needle:");
            string needle = Console.ReadLine();

            int match = BoyerMooreHorspool.Find(haystack, needle);

            Console.Clear();

            if (match == -1)
            {
                Console.WriteLine("No match");
                return;
            }

            Console.WriteLine("Match at char {0}", match);

            Console.WriteLine();
            Console.WriteLine(haystack);
            for (int i = 0; i < match; i++)
            {
                Console.Write(" ");
            }

            for (int i = 0; i < needle.Length; i++)
            {
                Console.Write("^");
            }
        }
コード例 #2
0
        private void materialFlatButtonTxrAra_Click(object sender, EventArgs e)
        {
            {
                Test3();
            }
            void Test3()
            {
                BoyerMooreHorspool bmh = new BoyerMooreHorspool();

                string    textveri = richTextBox2.Text;
                Stopwatch sw       = new Stopwatch();

                sw.Start();
                string     haystack = textveri;
                List <int> match    = new List <int>();



                string needle = patterntextfield.Text;

                match = bmh.Find(haystack, needle);

                if (true)
                {
                    if (match == null)
                    {
                        materialSingleLineTextField1.Text = "Eşleşme Yok!";
                        return;
                    }

                    materialSingleLineTextField1.Text = listBox1.SelectedItem + ". Karakterde eşleme var";

                    richTextBox1.Text = haystack;
                    //arbitrary numbers to test
                    for (int i = 0; i < match.Count; i++)
                    {
                        int blockLength = patterntextfield.TextLength;
                        richTextBox1.SelectionStart     = match[i];
                        richTextBox1.SelectionLength    = blockLength;
                        richTextBox1.SelectionBackColor = Color.Yellow;
                    }
                }
                sw.Stop();
                string ExecutionTimeTaken = string.Format("{0} dk:{1} sn:{2} milisn", sw.Elapsed.Minutes, sw.Elapsed.Seconds, sw.Elapsed.TotalMilliseconds);

                materialSingleLineTextField3.Text = ExecutionTimeTaken;
                materialSingleLineTextField2.Text = haystack.Length.ToString();
                int chars = metintextfield.Text.Length;

                materialSingleLineTextField2.Text = chars.ToString();
                materialSingleLineTextField5.Text = bmh.Karsi().ToString();
                materialSingleLineTextField6.Text = bmh.Esle().ToString();
                listBox1.DataSource = match;
            }
        }
コード例 #3
0
        public void Test()
        {
            BoyerMooreHorspool bmh = new BoyerMooreHorspool();

            string haystack = metintextfield.Text;



            string needle = patterntextfield.Text;

            //int match = bmh.Find(haystack, needle);
            List <int> match = new List <int>();

            match = bmh.Find(haystack, needle);

            if (true)
            {
                if (match == null)
                {
                    materialSingleLineTextField1.Text = "Eşleşme Yok!";
                    return;
                }

                materialSingleLineTextField1.Text = listBox1.SelectedItem + ". Karakterde eşleme var";

                richTextBox1.Text = haystack;
                //arbitrary numbers to test
                for (int i = 0; i < match.Count; i++)
                {
                    int blockLength = patterntextfield.TextLength;
                    richTextBox1.SelectionStart     = match[i];
                    richTextBox1.SelectionLength    = blockLength;
                    richTextBox1.SelectionBackColor = Color.Yellow;
                }
                int chars = metintextfield.Text.Length;
                materialSingleLineTextField2.Text = chars.ToString();
                materialSingleLineTextField5.Text = bmh.Karsi().ToString();
                materialSingleLineTextField6.Text = bmh.Esle().ToString();
                listBox1.DataSource = match;
            }
        }