Ejemplo n.º 1
0
        private void btnOsearch_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(this.txtPatternBox.Text) == true)
                {
                    throw new Exception("Pattern cannot be empty!");
                }
                else if (string.IsNullOrEmpty(this.txtFileInputBox.Text) == true)
                {
                    throw new Exception("Drop a text file into textbox file input");
                }
                else if (File.Exists(this.txtFileInputBox.Text.Trim()) == false)
                {
                    throw new Exception("File input does not exists!");
                }
                // Reset back-color
                var sstart = this.richTextBox1.SelectionStart;
                this.richTextBox1.Text           = this.richTextBox1.Text;
                this.richTextBox1.SelectionStart = sstart;
                // Parameters
                var osearch  = new OtomatSearch();
                var patterns = this.txtPatternBox.Text.Trim()
                               .Split(new char[] { '%' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < patterns.Length; i++)
                {
                    var next = this.btnEnableSearchNext.Checked == true ?
                               (this.richTextBox1.SelectionStart >= this.richTextBox1.TextLength - osearch.Next
                        ? 0 : this.richTextBox1.SelectionStart)
                        : osearch.Next;
                    var result = osearch.Osearch(this.richTextBox1.Text, patterns[i].Trim(), next, this.btnCheckPatternIsApproximate.Checked);
                    if (result < 0)
                    {
                        this.richTextBox1.Text = this.richTextBox1.Text;
                        MessageBox.Show("Pattern not found!", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        break;
                    }
                    // Tô màu
                    this.richTextBox1.Select(result, osearch.Length);
                    this.richTextBox1.SelectionBackColor = Color.Indigo;
                    this.richTextBox1.SelectionColor     = Color.White;
                    this.richTextBox1.SelectionStart    += osearch.Length;
                }

                this.richTextBox1.ScrollToCaret();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
        static void Main()
        {
            var s             = "ABC ABCDAB ABCDABCDABDE";
            var p             = "ABCDABD";
            var v_str_pattern = "PARTICIPATE IN PARACHUTE";
            var t             = "thông tư";
            var pa            = "Th.ng tư";
            var osearch       = new OtomatSearch();
            var i             = osearch.Osearch(t, pa, 0, true);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
        }