Get Count Of A Substring In A String Using Asp.Net C#

Get Count Of A Substring In A String Using Asp.Net C#

Give Input String To Textbox Get Count Without Using Loop Condition in Asp.Net C#.

                         DEMO



                               Download

                   HTML Coding


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Get Count Of A Substring In A String Using Asp.Net C#</title>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
   
        Input String
        <asp:TextBox ID="txtInput" runat="server"></asp:TextBox>
        Count String
        <asp:TextBox ID="txtCount" runat="server"></asp:TextBox>
       
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Count" />
        <asp:Label ID="lblCount" runat="server" Font-Size="Large" ForeColor="#FF0066"></asp:Label>
        <br />
   
    </div>
    </form>
</body>

</html>
                   C# Coding


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text.RegularExpressions;

public partial class _Default : System.Web.UI.Page
{    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int c = Regex.Matches(txtInput.Text.ToUpper(),txtCount.Text.ToUpper()).Count;

        lblCount.Text = c.ToString();
    }

}


First - Add New form - Select Textbox From Toolbox




Next - Add - Namespaces - Input String Change Regex.Matches - Get Count






0 comments:

Post a Comment