I am building a calculator app for iOS using DDMathParser. I would like to know how to separate an expression (NSString
) like 5+900/32
into its individual number values: 5
, 900
, and 32
. I would prefer that I get these in an NSArray
or other relatively useful list object. I have heard that there is an easy way to do this with DDMathParser
- It's why I switched from GCMathParser
.
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
DDMathParser author here.
Yes, this is very easy, and there are a couple of ways to go about it. If you simply want what the numbers are and don't care about the operators, you can use the tokenizing API:
There is, however, a caveat to this approach, and it can be best illustrated with this example:
@"-42"
. Tokens in DDMathParser are always parsed as unsigned numbers, because the minus sign in front is actually an operator and gets applied differently depending on other operators. That means that if you tokenize the string@"-42"
, you'll see that it contains two tokens: a negation operator, and the number 42.