There are 3 methods to substring a NSString.
NSLog([@"1234567890" substringFromIndex:4]); NSLog([@"1234567890" substringToIndex:6]); NSLog([@"1234567890" substringWithRange:NSMakeRange(3, 5)]);
There are 3 methods to substring a NSString.
NSLog([@"1234567890" substringFromIndex:4]); NSLog([@"1234567890" substringToIndex:6]); NSLog([@"1234567890" substringWithRange:NSMakeRange(3, 5)]);
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.
Ususally we use the Format Specifier in NSLog() to show the debug output. For Example:
NSString* name = @"Yuen Ying Kit"; int age = 26; NSLog(@"My name is %@", name); NSLog(@"I am %i years old", age);
Convert NSString to int
NSString *aNumberString = @"123"; int i = [aNumberString intValue];
Convert int to NSString
int aNumber = 123; NSString *aString = [NSString stringWithFormat:@"%d", aNumber];