我有一个表a1存着公式(如:a+b*c).各种公式。想用c# 将变量解析出来。
如:a b c不知道大家有没有什么好方法??最好是一个方法,将公式传进去。返回变量的数组。

解决方案 »

  1.   

    本帖最后由 caozhy 于 2012-11-17 23:14:36 编辑
      

  2.   

    如果一定要代码的话,可以参考:http://cn.bing.com/search?q=yacc+lex&qs=n&form=QBLH&pq=yacc+lex&sc=8-8&sp=-1&sk=
      

  3.   

    公式中的变量是一个代码,可以是a001什么地。比如a001+fy002*de003  之类的。
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string exp = "a001+fy002*de003";
                string[] vars = Regex.Matches(exp, @"[a-zA-Z]+\d*").Cast<Match>().Select(x => x.Value).ToArray();
                foreach (string item in vars)
                {
                    Console.WriteLine(item);
                }
            }
        }
    }a001
    fy002
    de003
    Press any key to continue . . .