I have an NSString that gets assigned a string value. How do I take this NSString and insert @"-thumbnail" between the file’s name and its extension?
In other words, how do I go from:
NSString *fileName = @"myFile.png";
to:
NSString *thumbnailName = [NSString someMagicFunction...]
NSLog(@"%@", thumbnailName); // Should Output "myFile-thumbnail.png"
The NSString additions for path components can come in handy, specifically: pathExtension and stringByDeletingPathExtension
Edit: see also: stringByAppendingPathExtension: (as pointed out by Dave DeLong)
If you really want that
magicFunctionto exist, you can add a category method to NSString like so:To be used as follows: