Bobby

Bobby

  • NA
  • 1
  • 0

Solve an expression stored in a string

Oct 27 2007 12:32 PM

Hello,

I'm using C# .NET 2005, and looking for an easy way to solve an expression stored in a string.  Here's an example:

string test;

decimal result;

test = "1+3";

result = Convert.ToDecimal(test);

I know this doesn't work, but is there anything I can do that would be similar to this? I'm hoping I don't have to parse the string for each value and each operator and then evaluate them myself.  Does .NET 2005 have anything that'll make this nice and easy?  My expression above is a simple one, but I will need to solve expressions which may be very long and include many operators such as Sin(), Sqrt, etc.

Thanks!


Answers (1)