I'm sending a sting expression to a function and want it to return the answer. I think i need to use parse but am not sure how.
e.g.
main function()
{
How to calculate a parsed expression (new to programming)
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Scott LysleRank #49 · 31K reputationPosted Apr 1, 2009, 8:46 PM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Apr 1, 2009, 10:13 PM EDT
ie
if i want to Parse only number from mix data String+Number
Following Function Finds Integer Values From String Data
public int Multiply(string Matchpattern,string str)
{
Regex rx = new Regex(Matchpattern);
Match m = s.Match(str);
int x = Convert.ToInt32(m);
return x*x;
}
Use this Function like
Multiply("[0-9]*","Sample text and Digit Data 12345");
Happy Coding :)
see program5 reputationPosted Apr 1, 2009, 10:57 PM EDT
anyway this is what i meant:
e.g.
main function(){
int ans = calculate ( "( 4 + 3 * 2) + -2 )" ); //returns 8
}
public static calculate (string expression){
?????????
return answer;
}
see program5 reputationPosted Apr 2, 2009, 11:41 AM EDT