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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -