0

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.

Matteo Gobbi
  • 17,697
  • 3
  • 27
  • 41
bettermab9
  • 65
  • 8

3 Answers3

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