[Solved] Adding math symbols in a string [closed]


int a = 10;
int b = 20;
NSString *c = @"+";

NSString *s = [NSString stringWithFormat:@"%d %@ %d", a, c, b];
NSExpression *e = [NSExpression expressionWithFormat:s];
int result = [[e expressionValueWithObject:nil context:nil] intValue];

NSLog(@"%d", result);

4

solved Adding math symbols in a string [closed]