求解具有bodmas方程的字符串 [英] solve a string having bodmas equation
本文介绍了求解具有bodmas方程的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的先生
i有一个像字符串str =(7 +((8%2)(7%3)的字符串)))如何解决这个等式它可能是任何类型(7 + 8(10/2)* 10)任何一个plz告诉我如何解决这个字符串。
Dear sir
i have a string having like string str= (7+((8%2)(7%3))) how to solve this equation it may be any type like (7+8(10/2)*10) can any one plz tell me how to solve this string.
推荐答案
请参阅此处:微小的表达评估器 [ ^ ]
您首先必须以C#兼容格式表达您的方程式。
如果括号中的两个不同表达式相邻,则C#不进行隐式乘法运算:
(7 +((8%2)(7%3)))不会用C#编译:(7 +((8%2)*(7%3) ))。
转换一个表示隐式乘法的字符串很容易:
You are first going have to express your equations in a C# compatible format.
C# does not do implicit multiplication if two different expressions in parentheses are adjacent:
(7+((8%2)(7%3))) will not compile in C#: (7+((8%2)*(7%3))) will.
Transforming a string that does express implicit multiplication is, however, easy:
string equationString = "(7+((8%2)(7%3)))";
string explicitMultiply = equationString.Replace(")(", ")*(");
但是,如果你有一个5(10)形式的表达式,并期望乘以5 x 10:那将需要另一种类型的修复。
But, if you had an expression of the form "5(10)," and expected that to multiply 5 x 10: that would require another type of fix.
这篇关于求解具有bodmas方程的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文