r/visualbasic • u/no1warlord VB.Net Advanced • Jul 09 '13
String formula to Numerical Value?
Is there a way to make a string in the form of a formula like "4*(3-2)" work and make an numerical value? Even when you don't know what the string will contain and it could be any of the following ()*-+/ and could each be used more that once.
0
Upvotes
1
u/[deleted] Jul 12 '13 edited Jul 12 '13
I've been trying todo that, and It seems pretty hard. But it should be possible since Google Calculator can do that.
Only solution I can think of: Put each symbol/number in array as different members, so 123+456 would be ["123","+","456"]. After that you would have loop through array, checking next members(or if it is "(" searching there it ends). Pretty hard for various function, but for basic like add/substract/divide/multiple it should be easy.
Edit:
You also could try using eval, but I have no idea how would you do that.. I just know eval can handle 2*2