Пример #1
0
        private void button_Search_Click(object sender, EventArgs e)
        {
            if (textBox_Pattern.Text.Length > textBox_Text.Text.Length)
            {
                MessageBox.Show("Pattern must be shorter than text!!", "Error");
                return;
            }
            if (textBox_Pattern.Text.Length == 0 || textBox_Text.Text.Length == 0)
            {
                MessageBox.Show("Please enter pattern and text!!", "Error");
                return;
            }

            SelectSeracher(radioButton_Naive_Search.Checked, radioButton_Rabin_Karp_Search.Checked, radioButton_Knuth_Morris_Pratt_Search.Checked);

            start_indexes = searcher.Search(textBox_Pattern.Text, textBox_Text.Text);
            textBox_Text.Select(0, textBox_Text.Text.Length);
            textBox_Text.SelectionColor = Color.Black;

            foreach (int index in start_indexes)
            {
                textBox_Text.Select(index, textBox_Pattern.Text.Length);
                textBox_Text.SelectionColor = Color.Red;
            }

            string plural_or_not;

            if (start_indexes.Count == 1)
            {
                plural_or_not = "";
            }
            else
            {
                plural_or_not = "es";
            }
            label_Message.Text = "Found: " + start_indexes.Count.ToString() + " match" + plural_or_not;

            searcher.ClearIndexes();
            start_indexes.Clear();
        }