Tag Archives: NSString

Objective-C – Substring a NSString

There are 3 methods to substring a NSString.

NSLog([@"1234567890" substringFromIndex:4]);
NSLog([@"1234567890" substringToIndex:6]);
NSLog([@"1234567890" substringWithRange:NSMakeRange(3, 5)]);

  Continue reading Objective-C – Substring a NSString

Objective-C – Convert NSString File Path to NSURL and Vice Versa

Convert NSString to NSURL

NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
/* OR */
NSURL *fileURL = [NSURL fileURLWithPath:filePath];


Convert NSURL to NSString

// The output string will have the file:// prefix
NSString *filePath= [fileURL absoluteString];

// The output string will have the file path only
NSString *filePath= [fileURL path];


Updated @ 2011-01-10: Thanks for the comments of Brandon and Antal.