我有一个字符串像ConsumerVisit(201)或日期(CX1)。我怎样才能得到括号内的字符串“(”“)”?如何获得括号之间的子字符串
我试了几次用下面的代码,但它在substringWithRange坠毁..
NSRange match;
NSRange match1;
match = [_actType.text rangeOfString: @"("];
match1 = [_actType.text rangeOfString: @")"];
NSLog(@"%i,%i",match.location,match1.location);
NSString *newDes = [_actType.text substringWithRange: NSMakeRange (match.location, match1.location-1)];
发生崩溃是因为您使用的NSMakeRange参数错误。第一秒应该是范围的长度,而不是其结束的位置。你的代码中的最后一行应该是这样的:'NSString * newDes = [_actType substringWithRange:NSMakeRange(match.location + 1,match1.location - match.location - 1)];' – filwag