tags:

views:

22

answers:

1

I have a string like this a web url

"http://stackoverflow.com/questions/3260091/databases-and-deep-copy"

how can i get the second to last section of the url?

3260091

+3  A: 
NSURL * url = [NSURL URLWithString:@"http://stackoverflow.com/questions/3260091/databases-and-deep-copy"];  //or however you get this url

NSString * path = [url path];
NSArray * components = [path pathComponents];

NSString * questionID = [components objectAtIndex:[components count]-2];
Dave DeLong
In OS 10.6 or later, you can send a `pathComponents` message directly to the `NSURL`, without converting to `NSString`.
JWWalker
this is so cool
Yazzmi
@JWWalker very true. I've been spending all of my time in 10.5-land :)
Dave DeLong