NSString到方程式

编程入门 行业动态 更新时间:2024-10-11 17:28:24
本文介绍了NSString到方程式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Objective-C,我正在尝试设置存储在 NSString 中的等式,以便进行评估并存储在 NSInteger中。

I am using Objective-C and I am trying to set an equation that is stored in an NSString to be evaluated and stored in an NSInteger.

类似于以下内容:

equation = [[NSString alloc] initWithString:@"1+5*6"];

然后将其评估为31并将其存储到 NSInteger 。任何想法如何做到这一点?

and then evaluate that to become 31 and store it into an NSInteger. any ideas how to do this?

推荐答案

你想要美妙,神奇,美妙的GCMathParser,(免费!) apptree: apptree/parser.htm 它完全符合您的要求,甚至允许你做变量替换(3x + 42,用x = 7评估)。它甚至支持数学函数,如sin(),cos(),tan(),它们的反转,dtor(),log(),....

You want the wonderful, amazing, and fabulous GCMathParser, available (FOR FREE!) on apptree: apptree/parser.htm It does exactly what you're asking, and even allows you to do variable substitutions (3x+42, evaluate with x = 7). It even has support for mathematical functions like sin(), cos(), tan(), their inverses, dtor(), log(), ....

很久以后编辑 ......

edit a long time later...

虽然GCMathParser非常棒,但它有一个不可扩展的缺陷。因此,如果您需要一个本身不支持的功能,那就太糟糕了。所以我决定对此做些什么,并想出了一个完全原生的数学解析器和评估器: http:// github。 com / davedelong / DDMathParser

While GCMathParser is pretty awesome, it has the flaw of not being extensible. So if you need a function that it doesn't natively support, then too bad. So I decided to do something about it, and came up with an entirely native math parser and evaluator: github/davedelong/DDMathParser

更多推荐

NSString到方程式

本文发布于:2023-11-29 18:40:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647272.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方程式   NSString

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!