Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
textbox contains 5 as input

expression is 5*x

string exp = textBox1.Text.ToString();
            string expression = exp.Replace("x", exp);
            txtCalculate.Text = expression;


I got this output

5*5*x
Posted
Updated 22-Nov-10 1:53am
v2
Comments
Manfred Rudolf Bihy 22-Nov-10 8:04am    
Ok: I tried your code in a test form, and the only way to get 5*5*x for the result is to put 5*x into textBox1.
Somethings afoul here ;)

Him

your code doesn't make sense. Is this what you want? (textBox1.Text is "5")
C#
string exp = "5*x";
string expression = exp.Replace("x", textBox1.Text);
txtCalculate.Text = expression; //5*5
 
Share this answer
 
v2
Comments
krishnakumar_L 22-Nov-10 8:05am    
Smart explanation
That's what you should get.
See the comments in the code:

C#
string exp = textBox1.Text.ToString(); //exp = 5*x
string expression = exp.Replace("x", exp); //expression = 5*(5*x) - I have replace x by value of exp
txtCalculate.Text = expression; //txtCalculate.Text=5*5*x


Where is the problem? Edit your question to add more information.

PS - I answered the question and deleted it because it seemed to appear twice. But later I realised it was other answer. So I wrote (rather pasted) it again.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900