Yazzmi
Yazzmi

Reputation: 1571

string manipulation with objective-c

I have a string like this a web url

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

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

3260091

Upvotes: 0

Views: 173

Answers (1)

Dave DeLong
Dave DeLong

Reputation: 243156

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];

Upvotes: 3

Related Questions