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()
{
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
see programPosted Apr 2, 2009, 3:41 PM
see programPosted Apr 2, 2009, 2:57 AM
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;
}
Kirtan PatelPosted Apr 2, 2009, 2:13 AM
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 :)
Scott LyslePosted Apr 2, 2009, 12:46 AM