using System.Collections.Generic;
public int Position { get; set; }
public int Difference { get; set; }
public int Nivel { get; set; }
public int Position { get; set; }
public int Length { get; set; }
public string Value { get; set; }
public static void Main(string[] args)
string round = "round((round((20 * (100-0 -0 - 0))/ 100, 2) + round((50 * (100-0-0-0))/100,2) + round ((30 * (100-0-0-0)) /100,2) + round((0*(100- - -))/100,2) + round((0 * (100 - - -) )/100,2)) / ((100-0) /100),2) % ";
string result = strEvaluate(round);
Console.WriteLine(result);
public static string strEvaluate(string strQualtrics)
DataTable dt = new DataTable();
Stack<Pointer> reader = new Stack<Pointer>();
Stack<Fragment> lstPartial = new Stack<Fragment>();
string strCalculo = "round(("+strQualtrics + "),2)";
strCalculo = strCalculo.Replace(" ", "");
while (strCalculo.IndexOf("--") >= 0)
strCalculo = strCalculo.Replace("--", "-");
while (strCalculo.IndexOf("++") >= 0)
strCalculo = strCalculo.Replace("++", "+");
strCalculo = strCalculo.Replace("-)", ")");
strCalculo = strCalculo.Replace("+)", ")");
for (int i = 0; i < strCalculo.Length; i++)
string s = strCalculo.Substring(i, 1);
diff = reader.Peek().Difference;
reader.Push(new Pointer() { Position = i + 1, Difference = diff });
Pointer ptReader = reader.Pop();
subtext = strCalculo.Substring(ptReader.Position, i - ptReader.Position);
textSize = subtext.Length;
if (lstPartial.Count > 0)
while (lstPartial.Peek().Nivel > reader.Count)
Fragment ptFragment = lstPartial.Pop();
subtext = subtext.Substring(0, ptFragment.Position-6) + ptFragment.Value +subtext.Substring(ptFragment.Position+3+ptFragment.Length);
if (lstPartial.Count == 0)
subtext = Math.Round(Convert.ToDouble(dt.Compute(subtext, "")), 2).ToString();
lstPartial.Push(new Fragment() { Nivel = reader.Count, Position = ptReader.Position - 6, Length = textSize, Value = subtext });
if (lstPartial.Count > 0)
result = lstPartial.Pop().Value;
if (strQualtrics.Substring(strCalculo.Length-1).Equals("%"))