How to remove selected string between parenthesis in xcode

Hi

if you got a string which contains comment between some special characters then you can use

– (NSString *)stringFilter:(NSString *)targetString {
    
    NSScanner *theScanner;
    NSString *text = nil;
    
    theScanner = [NSScanner scannerWithString: targetString];
    
    while ([theScanner isAtEnd] == NO) {
        
        [theScanner scanUpToString:@”{“ intoString:NULL] ; 
        
        [theScanner scanUpToString:@”}” intoString:&text] ;
        
        targetString = [targetString stringByReplacingOccurrencesOfString:
                      [NSString stringWithFormat:@”%@}”, text]
                                                           withString:@””];
        
    } 
    
    return targetString;
    
}
this code will remove all between the { } including them….Happy XCoding
A pat on the back !!

Leave a Reply

Your email address will not be published. Required fields are marked *