NSScanner扫描字符串中()的内容

时间:2024-07-09 19:06:02
//本事例去除小括号及其内部的内容
+ (NSString *)changeStringWithString:(NSString *)string
{
 NSScanner*scanner = [NSScanner scannerWithString:string];
 NSString*str =nil;
 while([scanner isAtEnd]==NO)
 {
 //找到"("的起始位置
 [scanner scanUpToString:@"("intoString:nil];
 //找到")"的结束位置
 [scanner scanUpToString:@")"intoString:&str];
 }
 NSString *lastString = [str stringByAppendingString:@")"];
 return lastString;
}