I want to extract variables from math expression using c#. I wrote this code and it works right:
List Variables = new List();
str
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.