I am trying to convert string to perform arithmetic expression but getting format expression. I want the expression to be calculated and final answer.
// original value
string text = @"4'-8"x5/16"x20'-8 13/16";
string path = text.Replace("'", "*12").Replace("-", "+").Replace("x", "+").Replace(" ", "+").Replace(@"""", "");
System.Console.WriteLine("The original string: '{0}'", text);
System.Console.WriteLine("The final string: '{0}'", path);
Console.WriteLine();
decimal d = decimal.Parse(path, CultureInfo.InvariantCulture);
Console.WriteLine(d.ToString(CultureInfo.InvariantCulture));
// after converting got this value in debug
//'4*12+8+5/16+20*12+8+13/16'
decimal.Parseis not going to evaluate a mathematical expression stored in a string. It doesn't work that way. You're going to have to extract the operands and do the math in your code.