my url is https://photos.googleapis.com/data/upload/resumable/media/create-session/feed/api/user/111066158452258/albumid/60281009241807
i want to extract the value of user
& albumid
, i had tried to extract with different methods which i found in stack overflow ,but they didn't work.
Please help me out.
Thank you for your precious time.
Asked
Active
Viewed 106 times
0

Matteo Gobbi
- 17,697
- 3
- 27
- 41

bettermab9
- 65
- 8
-
What methods did you try, so that we don't waste time giving you answers you've already tried? – El Guapo Jun 23 '14 at 13:14
-
Take a look on this answer http://stackoverflow.com/questions/3692947/get-parts-of-a-nsurl-in-objective-c – Ali Abbas Jun 23 '14 at 13:17
3 Answers
0
I give you an example here, NSURL class is your friend. You can use e.g. pathComponents
: to get an array of all components and then process this array as you need it:
NSURL *url = [NSURL URLWithString:@"https://photos.googleapis.com/data/upload/resumable/media/create-session/feed/api/user/111066158452258/albumid/60281009241807"];
NSArray *components = [url pathComponents];
NSLog(@"path components: %@", components);
NSLog(@"user: %@", components[9]);
NSLog(@"albumid: %@", components[11]);

Alexander
- 7,178
- 8
- 45
- 75
0
You can take your NSURL
(or init one from the URL string), and use the method pathComponents
which return an array of the words in the URL (separated from the slash /
), so:
pathComponents[0] == @"photos.googleapis.com"
pathComponents[1] == @"data"
...etc.
Here the snippet of code:
NSURL *url = [NSURL urlWithString:@"https://photos.googleapis.com/data/upload/resumable/media/create-session/feed/api/user/111066158452258/albumid/60281009241807"];
NSString *user = url.pathComponents[9];
NSString *album = url.pathComponents[11];

Matteo Gobbi
- 17,697
- 3
- 27
- 41
0
NSURL *url = [NSURL URLWithString:@"https://photos.googleapis.com/data/upload/resumable/media/create-session/feed/api/user/111066158452258/albumid/60281009241807"];
NSArray *pathComponentsArray = [url pathComponents];
NSString*userValue;
NSString*albumidValue;
for(int i=0;i<[pathComponentsArray count];i++)
{
if([pathComponentsArray[i] isEqualToString:@"user"])
{
userValue = pathComponentsArray[i+1];
}
if([pathComponentsArray[i] isEqualToString:@"albumid"])
{
albumidValue = pathComponentsArray[i+1];
}
}

Anrj
- 29
- 5
-
sir i am trying this method and then let you know,thank you for your kind assistance. – bettermab9 Jun 24 '14 at 05:18