开发者

c# calculation parser

Say I have a st开发者_运维百科ring like "(12.2*(5/7))", is there an API/method that can parse this or would I need to write one from scratch?

Thanks


Yes, there are such frameworks. Just google for '.NET expression parser' and you get plenty of results!


You'd need to write one or find a library to do this. There is nothing built into .NET to support this as standard.

One thing I've found myself considering when looking at problems like this is an Excel library (we already use one called FlexCel) which will handle all the standard Excel syntax and provide a rich suite of functions. You just end up excluding the excel specific ranges. The nice thing about this, is almost everyone knows how to use Excel functions already.


See the CodeProject.com article Implementing Programming Language Tools in C#. Included samples include an arithmetic evaluator and a JavaScript to expression tree compiler. Combining these should provide you with what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜