It’s easier to be told by example.
I have URLs like http://domain/product/view/id/. How can I get id out of the URL?
In my own opinion,
-
I can get the string between last two slash. But I need it to be flexible to handle extended URLs like
http://domain/product/view/id/title/. And I can neither expect the URLs to include the last slash. -
Match the prefix
http://domain/product/view/, then get the id before next slash. -
I love using regex in PHP, but there seems to be no built-in regex system in obj-c. So I need third party libs such as
RegexKitLite.
I want to discuss what’s the common or best way to implement such functions.
There are multiple ways of getting substrings
but in your case, since you’re dealing with URLs, one of the following might be better suited:
NSString componentsSeparatedByString:NSURL pathComponents: