ahmed

ahmed

  • NA
  • 2
  • 0

How to work with Power equation and expression in C#

Sep 26 2007 7:55 AM
all i want code when user
write any equations like this "(x^2+x)/(x*x)"
in text box 1
and write the value "x" in text box 2 , he has the value of this equation in message box when he press ok.
please, help me to get this code
and thank u .
and my problem , How can i write power expression in this code:
private void button1_Click(object sender, EventArgs e)
  {
  MessageBox.Show(Evaluate(textBox1.Text.Replace("x",textBox2.Text)).ToString());
  }
  public static double Evaluate(string expression)
  {
  return (double)new System.Xml.XPath.XPathDocument
  (new StringReader("<r/>")).CreateNavigator().Evaluate
  (string.Format("number({0})", new
  System.Text.RegularExpressions.Regex(@"([\+\-])")
  .Replace(expression, " ${1} ")
  .Replace("/", " div ")


Answers (1)