Showing posts with label lastPathComponent example. Show all posts
Showing posts with label lastPathComponent example. Show all posts

Saturday, May 18, 2013

NSString lastPathComponent example ios


[NSString lastPathComponent]

Returns the last path component of the receiver.
- (NSString *)lastPathComponent
Return Value
The last path component of the receiver.
Discussion of [NSString lastPathComponent]
Path components are alphanumeric strings delineated by the path separator (slash “/”) or the beginning or end of the path string. Multiple path separators at the end of the string are stripped.
Example of [NSString lastPathComponent]
NSString *filename = [filePath lastPathComponent];
[encryptedData writeToFile:[[NSHomeDirectory() stringByAppendingPathComponent:@"Desktop"] 
    stringByAppendingPathComponent:[filename stringByAppendingString:@".kry"] atomically:YES];
Example of [NSString lastPathComponent]
NSURL *url = [NSURL urlWithString:@"http://www.google.com/a.pdf"];
NSString *filename = [url lastPathComponent];
NSString* theFileName = [[string lastPathComponent] stringByDeletingPathExtension]

Example of [NSString lastPathComponent]
NSString *fullPath = // Get the path to your image
NSString *pathWithNoFileName = [fullPath stringByDeletingLastPathComponent];
NSString *myPath = [[pathWithNoFileName lastPathComponent] stringByAppendingPathComponent:[fullPath lastPathComponent]];

Wednesday, May 1, 2013

NSURL lastPathComponent example ios

lastPathComponent
Returns the last path component of a file URL.
- (NSString *)lastPathComponent
Return Value of [NSURL lastPathComponent]
The last path component of the URL.
Example of [NSURL lastPathComponent]
NSString* s = @"http://www.somewhere.org/foo/bar.html/#label";
NSURL* u = [NSURL URLWithString:s];

// Get the last path component from the URL. This doesn't include
// any fragment.
NSString* lastComponent = [u lastPathComponent];

// Find that last component in the string from the end to make sure
// to get the last one
NSRange fragmentRange = [s rangeOfString:lastComponent
                                 options:NSBackwardsSearch];

// Chop the fragment.
NSString* newURLString = [s substringToIndex:fragmentRange.location + fragmentRange.length];

NSLog(@"%@", s);
NSLog(@"%@", newURLString);
Example of [NSURL lastPathComponent]
NSURL *url = [NSURL urlWithString:@"http://www.google.com/a.pdf"];
NSString *filename = [url lastPathComponent];