Markissimo
Markissimo

Reputation: 329

Eval arithmetic expression windows phone7?

Is there any API for WP7 to get an arithmetic expression in a string and eval it?

Searched for it on google, but nothing comes up..

Thanks in advance.

Upvotes: 0

Views: 101

Answers (1)

gjulianm
gjulianm

Reputation: 834

Searching for "C# parse arithmetic from string" I found a good bunch of resources, with this one the most appealing to me. I haven't tried, but I suppose it will compile on WP7.

Anyways, there's always the possibility of building your own parser. You can approach this using expression trees: read about this in this article (scroll down to the section Expression Trees) (in Java, but explains the concept pretty well and the language is similar enough to C# to be comprehensible).

You can also use the Shunting Yard algorithm, which uses a stack to evaluate the expression. These are only two approachs I remember now, I'm sure there are a lot more. It's harder than using third party libraries, but you can adapt them to your own requeriments.

Upvotes: 1

Related Questions