G
Guest
I have a string that contains math problems with numbers and operators. I
need to assign the solution to a variable. See examples below.
My first thought was to use split with "+" as my delimiter. Worked great!
Problem is that the string can have any combination of +, -, *, and /
operators or no operators at all.
Anyone have a suggestion?
Examples:
String ; Result
"15" ; 15
"10+5" ; 15
"20-5" ; 15
"10+7-2" ; 15
"30/3+5" ; 15
"-5+20" ; 15
Notice the minus sign in the last example. If a minus sign is the first
character then the first number is negative.
need to assign the solution to a variable. See examples below.
My first thought was to use split with "+" as my delimiter. Worked great!
Problem is that the string can have any combination of +, -, *, and /
operators or no operators at all.
Anyone have a suggestion?
Examples:
String ; Result
"15" ; 15
"10+5" ; 15
"20-5" ; 15
"10+7-2" ; 15
"30/3+5" ; 15
"-5+20" ; 15
Notice the minus sign in the last example. If a minus sign is the first
character then the first number is negative.