Im trying to write a method that will pull out the ID from a URI String. My code below seems inefficient, what would be a better way of finding the id string?
NSString *aID = [[[NSString alloc] initWithString:@"http://www.example.com/id368907840?mt=8&uo=4"] autorelease];
NSArray *arrStr = [aID componentsSeparatedByString:@"/id"];
aID = [arrStr objectAtIndex:1];
arrStr = [aID componentsSeparatedByString:@"?mt="];
aID = [arrStr objectAtIndex:0];
The above leaves me with the NSString = 368907840
You can use NSURL -lastPathComponent, NSString -stringByTrimmingCharactersInSet, and NSCharacterSet +letterCharacterSet to accomplish the same task as in the following example:
Disclaimer: I haven’t actually tried this, so you will need to try it yourself, but I believe this should work.