Skip to content

Solve an expression stored in a string

Bobby

Asked Oct 27, 2007, 8:32 AM EDT1 answer
Share
LinkedInX

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:

Code
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!

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    Hi,

    A possible solution is CodeDom, see here for more.

    Sam

    0