nsstring - Objective C : Find number of operators in a mathematical string -
i'm using following technique find number of operators in mathematical string.
for (int index = 0; index < [self.evaluatestring length]; index++) { unichar chars = [self.evaluatestring characteratindex:index]; if (chars == '+' || chars == '-' || chars == '*' || chars == '/' ||chars == '^') { self.operatorcount++; } }
my trainer says method not good. know there better/more elegant method this. thanks.
it seems string evaluated. part of evaluation parsing. during process mathematical operators identified , counted.
the advantage on simple character counting tell apart 3 - 1
(operator) -1
(negative number literal).
Comments
Post a Comment