我做了一些代码来计算某个字符串中的每个括号,
有没有更简单的方法?
NSCharacterSet *parenthesis = [NSCharacterSet characterSetWithCharactersInString:@"()"];
parenthesis = [parenthesis invertedSet];
NSArray *arr = [someString componentsSeparatedByCharactersInSet:parenthesis];
NSInteger count = 0;
for(int i=0;i<[arr count];i++) {
if([[arr objectAtIndex:i] isEqualToString:@")"])
count++;
}
NSLog(@"count is %d", count);