Maths Problem:
endParenthesis.location - beginParenthesis.location + 1 gives u ( 5 - 1 + 1) i.e equal to5 . But endParenthesis.location - start gives u 5 - 2 i.e 3.
So you put the parenthesis like this:
NSLog(@"%ld", endParenthesis.location - (beginParenthesis.location + 1));