I have a string!
NSString *myString=[NSString stringWithFormat:@"This is my lovely string"];
What I want to do is:
Substring the remaining string to a new string using ...
[myString substringFromIndex:leSpace]
...I hope I have explained well. Please help, can you write a snippet or something to help me do this task?
- (NSRange)rangeOfString:(NSString *)aString options:(NSStringCompareOptions)mask range:(NSRange)aRange
For the options use: NSBackwardsSearch
NSRange range = [myString rangeOfString:@" " options:NSBackwardsSearch range:NSMakeRange(0, 11)];
Example:
NSString *myString=[NSString stringWithFormat:@"This is my lovely string"];
NSRange range = [myString rangeOfString:@" " options:NSBackwardsSearch range:NSMakeRange(0, 11)];
NSLog(@"range.location: %lu", range.location);
NSString *substring = [myString substringFromIndex:range.location+1];
NSLog(@"substring: '%@'", substring);
NSLog output:
range.location: 10
substring: 'lovely string'
Of course there should be error checking that range.location
does not equal NSNotFound