Extract variables from string math expression

前端 未结 3 1523
时光取名叫无心
时光取名叫无心 2020-12-11 11:14

I want to extract variables from math expression using c#. I wrote this code and it works right:

List Variables = new List();
str         


        
3条回答
  •  时光说笑
    2020-12-11 11:54

    If you want parse experssion yourself, your ways seems good, but it doesn't evaluate it, in this cases I prefer to use previous wrote parsers like NCalc, instead of creating the wheal, but if this is a homework and you just want to find variables, your way can be optimized by for example doing temp += Expression[Index];, Also may be using Experssion.Split(... works better in this case. and if you want parse it yourself you can use shutting yard algorithm.

提交回复
热议问题