数学评估用户定义的变量 [英] mathematic evaluation user defined variable

查看:78
本文介绍了数学评估用户定义的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上。我在想如何分别根据用户定义的变量来评估数学方程。例如

假设用户输入(y4df + rew)/ 4dwcf * rt

当用户点击评估时,它会提示用户输入变量值,如下所示

y4df =?

重新=?

4dwcf =?

rte =?



任何解决此问题或教程的建议。我打算在vb.net中这样做

tq。

Hai. I was thinking how to evaluate mathematical equations based on user defined variable separately. for example
let say user input (y4df +rew)/4dwcf*rte
when user click evaluate, it will prompt user to input values for variables as below
y4df = ?
rew= ?
4dwcf=?
rte= ?

any suggestion for solve this problem or tutorial. i plan to do it in vb.net
tq.

推荐答案

我有另一个建议:你可以在适当的位置放置一个表达式字符串C#或VB.NET程序文本,使用CodeDOM构建它(如果存在编译错误),将结果程序集加载到Application Domain中,执行包含表达式的方法,如果需要,显示结果(在您的原始Application Domain中) UI),删除应用程序域。它运行得非常快,那些编译器是.NET Framework的一部分,它们总是可供用户使用,并通过CodeDOM调用。



此外,这种方式是非常非常可靠,它依赖于经过良好调试和测试的编译器和CLR。



我提供了详细的解释,并在我过去的答案中进一步引用:

使用CodeDom生成代码 [ ^ ],

创建使用可重新加载插件的WPF应用程序... [ ^ ]。



-SA
I have an alternative suggestion: you can put an expression string in appropriate C# or VB.NET program text, build it using CodeDOM (present compilation errors if any), load the resulting assembly in an Application Domain, execute the method containing the expression, if required, present the result (in your original Application Domain of you UI), delete the Application Domain. It works very quickly, and those compilers are a part of .NET Framework, they are always available to the user and are invoked via CodeDOM.

Also, this way is very, very reliable, it relies on available well debugged and tested compilers and CLR.

I provided detailed explanations and further referenced in my past answers:
code generating using CodeDom[^],
Create WPF Application that uses Reloadable Plugins...[^].

—SA


我建​​议使用正则表达式来查找数学运算符并将字符串拆分为这些运算符。



System.Text.RegularExpressions [ ^ ]



看起来它有拆分方法 [ ^ ]。我之前从未使用过它......我之前使用过替换方法。但是我确定你可以在开始尝试之后谷歌找到更具体的例子。



如果你以前从未使用过正则表达式,你可能也想先研究一下。以下是关于CP的一篇(很可能很多)文章,可以帮助您入门: The 30分钟正则表达式教程 [ ^ ]
I would suggest using regular expressions to find the mathematical operators and split the string on those.

System.Text.RegularExpressions[^]

It looks like it has a Split Method[^]. I''ve never used it before...I''ve used the Replace Method before. But I''m sure you can google for more specific examples once you get started trying it out.

If you haven''t ever worked with Regular Expressions before, you might want to research that first too. Here is one (of probably many) articles on CP that could help get you started: The 30 Minute Regex Tutorial[^]


我建​​议您使用关键词Pascal Ganaye评估员进行搜索。他的代码(vb.net)肯定会帮助你。
I suggest you to search with the key word "Pascal Ganaye evaluator". His code (vb.net) will help you, definitely.


这篇关于数学评估用户定义的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆