Convert to Float and Calculate

后端 未结 3 1562
无人共我
无人共我 2020-12-11 14:00

I have a string with multiple digits and operators

@\"5+4-9/10\".

How to get the result from it?

I want to use it within the calculator

3条回答
  •  隐瞒了意图╮
    2020-12-11 14:57

    You could parse "all" numbers to float:

    NSMutableString *numericExpression = [NSMutableString stringWithString:@"4+3/2-7/4"];
    
    NSMutableString *nExp=[NSMutableString stringWithString:@""];
    BOOL innum=false;
    BOOL dotfound=false;
    
    for (NSInteger charIdx=0; charIdx

提交回复
热议问题