Need to remove string which in between the braces

☆樱花仙子☆ 提交于 2019-12-08 05:08:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!