views:

36

answers:

2

I want to replace the text in a string "Sin()" with the computed value for Math.Sin() where is...anything.

My problem: The string can have more than one right parenthesis. Also, since it is performing mathematical operations, it would have to know how to do the innermost ones first.

Obviously, there is not a built in method for computing mathematical equations (well, nothing that is SUPPOSED to be used for that), as noted in a previous question of mine.

This is very tricky, can anyone help?

A: 

There's a good example of an expression parser and evaluator in vb.net here, I imagine you can study and modify those sources (it also offers clear text explanations).

Alex Martelli
+1  A: 

You want to tokenize your input text, and then parse your tokens. As Alex Martelli points out, CodeProject also has a good example of something similar (which I was able to find in <10 seconds with Google).

Daniel Pryden