REGEX

July 9, 2008 – 11:17 am
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string str = textBox2.Text;
            string find = textBox1.Text;

            MatchCollection Matches = Regex.Matches(str, find, RegexOptions.IgnoreCase);
            listBox1.Items.Clear();
            this.listBox1.Items.Add(textBox1.Text.ToString());

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            string str = textBox2.Text;
            string find = textBox1.Text;

            MatchCollection Matches = Regex.Matches(str, find, RegexOptions.IgnoreCase);
            listBox1.Items.Clear();
            foreach (Match NextMatch in Matches)
            {
                this.listBox1.Items.Add(NextMatch.ToString());
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            string str = textBox2.Text;
            string find = textBox1.Text;

            MatchCollection Matches = Regex.Matches(str, find, RegexOptions.IgnoreCase);
            listBox1.Items.Clear();
            if (Matches.Count == 0)
            {
                listBox1.Items.Add("There are no matches");
            }
            else
                listBox1.Items.Add("Matches found");
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}


No comments yet.

Post a Comment


Anti-spam measure: please retype the above text into the box provided.