/* StrExpr1 - Calculates a simple binary expression in a string and returns the result as a number DESCRIPTION Calculates a simple binary expression in a string and returns the result as a number. No spaces and no parentheses are allowed. Supported math operations are +, -, *, /, ^, and %. A simple number string is also accepted and converted to a number. SYNTAX iNum StrExpr1 Str INITIALIZATION Str - Input string with a simple binary math expression. Supported math operations are +, -, *, /, ^, and %. No spaces and no parentheses are allowed. A simple number string is also accepted and converted to a number. iNum - result of the binary operation as number CREDITS joachim heintz 2012 */ opcode StrExpr1, i, S Str xin isum strindex Str, "+"; sum idif strindex Str, "-"; difference ipro strindex Str, "*"; product irat strindex Str, "/"; ratio ipow strindex Str, "^"; power imod strindex Str, "%"; modulo if ipow > 0 then ifirst strindex Str, "^" S1 strsub Str, 0, ifirst S2 strsub Str, ifirst+1 i1 strtod S1 i2 strtod S2 ires = i1 ^ i2 elseif imod > 0 then ifirst strindex Str, "%" S1 strsub Str, 0, ifirst S2 strsub Str, ifirst+1 i1 strtod S1 i2 strtod S2 ires = i1 % i2 elseif ipro > 0 then ifirst strindex Str, "*" S1 strsub Str, 0, ifirst S2 strsub Str, ifirst+1 i1 strtod S1 i2 strtod S2 ires = i1 * i2 elseif irat > 0 then ifirst strindex Str, "/" S1 strsub Str, 0, ifirst S2 strsub Str, ifirst+1 i1 strtod S1 i2 strtod S2 ires = i1 / i2 elseif isum > 0 then ifirst strindex Str, "+" S1 strsub Str, 0, ifirst S2 strsub Str, ifirst+1 i1 strtod S1 i2 strtod S2 ires = i1 + i2 elseif idif > -1 then ifirst strrindex Str, "-";(last occurrence: -3-4 is possible, but not 3--4) S1 strsub Str, 0, ifirst S2 strsub Str, ifirst+1 iS1len strlen S1 if iS1len == 0 then ;just a negative number inum strtod S2 ires = -inum else ifirst strtod S1 isec strtod S2 ires = ifirst - isec endif else ires strtod Str endif xout ires endop