NSString *thePath = @"new/path - path/path/03 - filename.ext"; NSString *lastPathComponent = [thePath lastPathComponent];
Edit to respond to your request. You do not need NSScanner:
NSString *thePath = @"new/path - path/path/03 - filename.ext"; NSRange theRange = [thePath rangeOfString:@"/" options:NSBackwardsSearch]; NSString *lastPathComponent = nil; if (theRange.location != NSNotFound) lastPathComponent = [thePath substringFromIndex:theRange.location];
user155959
source share