how to get result of string "4+5-6*1"

You must Login before you can answer or comment on any questions.

i am making a calculator as my first app and i want that user can enter a complete statement as string eg. "4+5-6*1".. can anyone tell me how to get a result from such a string?

— asked 10 months ago by hamza rauf
0 Comments

3 Answers

Accepted Answer

Have you tried eval ?

eval("4+5-6*1") -> 3

Hi Hamza,

You can get result using string function like split function and after you get individual object do your calculation.

— answered 10 months ago by Nitin Chavda
answer permalink
1 Comment
  • thanks but i have have used split function, i was wondering if there is another function ,like parsing, which directly gives you the arithmetic expression or result.. as it is a calculator it can get any combination of operators..

    — commented 10 months ago by hamza rauf

Your Answer

Think you can help? Login to answer this question!