1

Is it possible to assign an int variable a value that is a result of expression written in a string? E.g. I have a string "5 - 3" and the expected result is 2.

2

3 Answers 3

4

You can use Calculator.NET

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I believe that is what I need.
1

If you fancy writing your own (I did, it's fun!). Have a look on Wikipedia for:

Shunting Yard Algorithm and Reverse Polish Notation

The pseudo-code is really clear and it's a great learning experience

Comments

-1

There is nothing built into the framework, so you can either built your own mathematical expression parser, or use one of the many libraries out there.

A search on ".net arithmetic parser" comes up with many results, some free, some not.

For instance:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.