本帖最后由 only1573 于 2012-09-24 14:59:51 编辑

解决方案 »

  1.   


    using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str = "a * (b - c)";
                string str1 = "2*(10-9.5)";
                string str2 = Compute(str1);
                Console.WriteLine(str);
                Console.WriteLine(str1);
                Console.WriteLine(str2);
                Console.ReadLine();
            }        static string Compute(string str)
            {
                string a = str.Substring(0,str.IndexOf('*'));
                string b = str.Substring(str.IndexOf('(')+1,str.IndexOf('-')-str.IndexOf('(')-1);
                string c = str.Substring(str.IndexOf('-')+1, str.IndexOf(')') - str.IndexOf('-') - 1);
                double temp = Convert.ToDouble(a) * (Convert.ToDouble(b) - Convert.ToDouble(c));;
                return Convert.ToString(temp);
            }
        }
    上面写的是一个控制台程序,参考
      

  2.   

    string str = Convert.ToDecimal(a)*(Convert.ToDecimal(b)-Convert.ToDecimal(c)).ToString();
      

  3.   

    其实这个只是其中一个点,全部的应该是还有if判断的,那个加这个才是我真正要做的。
    这个有人帮忙找到结果了。
    自己解析难写不说,效果也不会好哪去,采用了动态编译。
    因为可能会缺;,所以没有用C#,用的是ScriptEngine
      

  4.   

    http://topic.csdn.net/u/20110430/02/a3a306f8-2e21-4271-b3c5-35e2018933be.html