Expression Evaluation Problem in c# (equation)

Hi,
I am having a strnig variable which conatins a expression like 2*4+(9+9) etc..
when i try to evaluate this expression by using double.parse or convert.toDouble methods.. it throws me stringformatexception..
Please help
Thanks
Rohit SaxenaTongue Tied
[332 byte] By [RohitSaxena] at [2007-12-16]
# 1
Hi,
Double.Parse and Convert.ToDouble functions just converts the string data into a Double. It does not performs calculations, even if you specify it on your string. Your string var is indeed invalid, valid string inputs must all be numerical. If you want to evaluate that expression you'll have to do the logic to parse each char and perform the reauired calculation (since im not aware of any .net class that would do the trick)

cheers,
Paul June A. Domag

PaulDomag at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
A simple method, but not perfect:
new DataTable().Compute("2*4+(9+9)", null);
Wesele at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified