nOOb iOS
nOOb iOS

Reputation: 1394

Delete specific part of String in Objective-C

I have a string which comes as Filename [1234568]. I need to delete the square bracket part of the string and just get the filename. How can we retrieve just the file name?

Upvotes: 0

Views: 106

Answers (1)

Dipak Kacha
Dipak Kacha

Reputation: 423

Below Regex may help you

NSMutableString *str = [@"Filename [1234568]" mutableCopy];
NSRegularExpression *regex = [NSRegularExpression         
                              regularExpressionWithPattern:@"\\[.+?\\]"
                              options:NSRegularExpressionCaseInsensitive
                              error:NULL];

NSString *newStr = [regex replaceMatchesInString:str 
                      options:0 
                        range:NSMakeRange(0, [str length])  
                 withTemplate:@""];

Upvotes: 1

Related Questions