C# Regex Matches Count

Posted: July 20, 2014 in C#
Tags: ,

Bu projemizde herhangi bir metin belgesinde aradığımız bir kelimeden kaç tane var onu bulucaz.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

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

private void textBox2_TextChanged(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{

if (Regex.IsMatch(textBox2.Text, “^\\s*$”))
{
MessageBox.Show(“Text is empty”);
}
else
{
MessageBox.Show(” Total found::”+ Regex.Matches(textBox2.Text, textBox1.Text, RegexOptions.Multiline).Count );
}

}
}
}

regex

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s