-
string to operator
Lets say that I have a string - inside the string is a sum that reads 3 + 4
Now I read the string a char at a time and know how to sperate the int values, but is it possible to convert the + operator so that I can get VB.net to carry out this sum? just as I can convert strings into a int32 value, can I convert the + into a operator value?
Any help would be cool
thanks :-)
-
Hi,
When reading each character and you come to a number, store the number in the first element of a numerical array. If the next character is also a number, multiply the stored array value by 10 and add the next number. Continue until you get to an arithmetical operator and then store that in the first element of a string array. Similarly, store the next number characters in the second element of the numerical array. Repeat the process until the end of the string.
You then take the first element of the numerical array and apply the operator contained in the first element of the string array to it and the number in the second element of the numerical array etc.
You will have to amend this so as to apply correct arithmetic preference when you come accross multiple calculations.