Remove Textbox Particular Character Using Asp.Net C#

Remove Textbox Particular Character

If Textbox Enter Some Character Want to Remove After Particular Character use Below Coding in Asp.Net C#.


                       Download Coding
                                       Download
         
                              DEMO
HTML CODING


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
       
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Remove  @" />
        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Remove @+1" />
        <asp:Label ID="Label1" runat="server" ForeColor="#FF0066"></asp:Label>
    </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;
using System.Text.RegularExpressions;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }   
    protected void Button1_Click1(object sender, EventArgs e)
    {
       string Remove = TextBox1.Text.Substring(0, TextBox1.Text.IndexOf("@")); // Remove before @
        Label1.Text = Remove.ToString();    
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string Remove = TextBox1.Text.Substring(0, TextBox1.Text.IndexOf("@") + 1); // Remove Upto @
        Label1.Text = Remove.ToString();
    }

}


First Create New Webform - Add Label,Textbox,Buttons From Toolbox 





Next - Code Behind - Add Substring Method Remove Indexof  Textbox






0 comments:

Post a Comment