Beispiel #1
0
        public string GetResult(string input)
        {
            Initiailize();

            if (!_stringEvaluationValidator.Validate(input))
            {
                return("String not valid");
            }

            foreach (Match m in Regex.Matches(input, @"(\d+)([-+/*])?"))
            {
                if (!string.IsNullOrEmpty(m.Groups[2].ToString()))
                {
                    _numbers.Add(Convert.ToDouble(m.Groups[1].ToString()));
                    _operators.Add(m.Groups[2].ToString());
                    continue;
                }

                _numbers.Add(Convert.ToDouble(m.Groups[1].ToString()));
            }

            Evaluate();

            return(_numbers[0].ToString(CultureInfo.InvariantCulture));
        }
        public string GetResult(string input)
        {
            if (!_stringEvaluationValidator.Validate(input))
            {
                return("String not valid");
            }

            var    output       = new DataTable().Compute(input, null);
            double doubleOutput = Convert.ToDouble(output);

            return(doubleOutput.ToString(CultureInfo.InvariantCulture));
        }