Created
February 21, 2012 05:38
-
-
Save eduardordm/1873995 to your computer and use it in GitHub Desktop.
Good lord, where is NSString replaceWithPattern: ?!?!?!?!??!!?!?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int count = 1; | |
while ( [[NSFileManager defaultManager] fileExistsAtPath:[self filePath]] ) { | |
NSRegularExpression *regex = | |
[NSRegularExpression regularExpressionWithPattern:@"\\s\\(\\d\\)" | |
options:NSRegularExpressionCaseInsensitive | |
error:NULL]; | |
NSString* str = [regex stringByReplacingMatchesInString:self.name | |
options:0 | |
range:NSMakeRange(0, [self.name length]) | |
withTemplate:@""]; | |
[self setName:[NSString stringWithFormat:@"%@ (%d)", str, count] ]; | |
count++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment