Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by NoName115 · Jan 18, 2016 at 11:04 AM · c#textmathcalculation

Calculate arithmetic problem from text

Is there any simple way,function or dictionary that can solve simple math problem (2 + 5 * 8), and give me result in C#?? But if something like this exist in JavaScript, i am free to use it. Or i need code my own calculator?

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image antx · Jan 18, 2016 at 11:15 AM 0
Share

Not clear what you want here. You mean processing a string that contains something like (2 + 5 * 8) ?

avatar image NoName115 antx · Jan 18, 2016 at 11:54 AM 0
Share

Yes, get result from text, and that text is simple math problem, like (2 + 5 * 8).

avatar image saschandroid · Jan 18, 2016 at 12:49 PM 0
Share

There is an example in the msdn on how to solve simple math calculations with String.Split method here (first example). Perhaps you could code your own based on this.

avatar image Pangamini saschandroid · Jan 18, 2016 at 12:52 PM 0
Share

That wouldn't handle parentheses or any operator priority, would it?

avatar image NoName115 saschandroid · Jan 18, 2016 at 12:55 PM 0
Share

Thank you.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Pangamini · Jan 18, 2016 at 11:42 AM

You could write your own stack based expression interpreter, which is really not that complicated. You could even make this interpreter to create a .net DynamicMethod by emitting IL code, practially creating a code at runtime, making its execution super fast (provided you want to evaluate the same expression more than once).

Another option would be to use lua interpreter, or another language (for my ingaeme console i internally use Boo compiler, the same language that was recently dropped support for by unity).

But if you want to exercise yourself, trying to write your own stack based expression evaluator is not that much work

Note: CLI language compilers usually emit assemblies, which cannot be unloaded once loaded. This can be an advantage when you call the same expression more times (basically you create and load a DLL at runtime), but if you need to evaluate different string every frame, this will soon fill the memory

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

59 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Calculation with values over 2 billion 1 Answer

Radius too long 1 Answer

Display CPU usage on a UI Slider or Text 1 Answer

How to display text from a text object to another text object? 1 Answer

How do I make an external text document show only between certain lines in UI Text 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges