问题
I need to Remove some extra string that which coming in between the "(" ")" is this possible?. If so kindly tell me the way that need to do.
For example "Lead Programmer Analyst(#5641)". I need to remove the string #5641 that which is between ( and ).
Thank you, S.
回答1:
pass Your string to the below method , it will return the proper string
- (NSString *)stringCleaner:(NSString *)yourString {
NSScanner *theScanner;
NSString *text = nil;
theScanner = [NSScanner scannerWithString:yourString];
while ([theScanner isAtEnd] == NO) {
[theScanner scanUpToString:@"(" intoString:NULL] ;
[theScanner scanUpToString:@")" intoString:&text] ;
yourString = [yourString stringByReplacingOccurrencesOfString:
[NSString stringWithFormat:@"%@)", text]
withString:@""];
}
return yourString;
}
来源:https://stackoverflow.com/questions/5217484/need-to-remove-string-which-in-between-the-braces