How we can add the two number
sir how we can add the two number if user input the character with digit and truncate the char and take the digit from both input.and print the result after eliminate char from input value
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pankaj Rawat71 reputationPosted Apr 7, 2013, 11:48 PM EDT
add a namespace
using System.Text.RegularExpressions;
and on button click
Protected Void BtnAdd_Click(Object sender,EventArgs e)
{
string str1=txtstr1.Text;
string str2=txtstr2.Text;
int First_Value=Convert.ToInt32(Regex.Replace(str1, "[^0-9]", ""));
int Second_Value=Convert.ToInt32(Regex.Replace(str2, "[^0-9]", ""));
int Result=First_Value+Second_Value;
}
Satyapriya NayakRank #47 · 31.5K reputationPosted Apr 7, 2013, 11:49 PM EDT
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;
namespace WebApplication18
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
TextBox2.Text = Regex.Replace(TextBox1.Text, "[^0-9]", "");
TextBox4.Text = Regex.Replace(TextBox3.Text, "[^0-9]", "");
Response.Write(Convert.ToDouble(TextBox2.Text) + Convert.ToDouble(TextBox4.Text));
}
protected void Page_Load(object sender, EventArgs e)
{
TextBox2.Visible = false;
TextBox4.Visible = false;
}
}
}