开发者

convert an array of string values to use as a formulas

开发者 https://www.devze.com 2023-03-25 06:09 出处:网络
I am new to coding and obje开发者_JAVA百科ctive C so thanks for the help in advance. I have a .plist file containing an array of strings filled with formulas such as

I am new to coding and obje开发者_JAVA百科ctive C so thanks for the help in advance.

I have a .plist file containing an array of strings filled with formulas such as

*5.3

/2

-10.5

I am able to retrieve these string values from the .plist file but I am getting a little stuck trying to append these string formulas to existing variables with the hopes of returning a converted number. For example I would like to use my variable 7 with the formula *5.3 and return 37.1

7 *5.3 -> 37.1

Any help would be greatly appreciated


Appending the string to a variable is straightforward; it can be accomplished with something like this:

NSString *equation = [NSString stringWithFormat:@"%d%@", variable, plistEntry];

You'll run into problems when you want to evaluate this equation, however. This SO question discusses expression evaluation in Objective-C. Dave DeLong's answer links to a couple of libraries that you may want to look into: DDMathParser and GCMathParser.


This can't be done as-is. You'll need one of the many free expression evaluators (probably in C) that float around on the web.

See this SO question.

0

精彩评论

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