Skip to content

Instantly share code, notes, and snippets.

@eduardordm
Created February 21, 2012 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardordm/1873995 to your computer and use it in GitHub Desktop.
Save eduardordm/1873995 to your computer and use it in GitHub Desktop.
Good lord, where is NSString replaceWithPattern: ?!?!?!?!??!!?!?
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