0

I´m working on an app that displays 6 pictures from a website. These pictures change over time so I extracted the sourcecode of said website and managed to pull the first of the 6 pictures with this code:

NSError *error = nil;
NSString *deviantStringPopular;
deviantStringPopular = [NSString stringWithContentsOfURL:[NSURL     URLWithString:@"http://browse.deviantart.com/?order=24"]
                                         encoding:NSISOLatin1StringEncoding
                                            error:&error];
NSString *popularContent;
NSRange popularURLRange1 = [deviantStringPopular rangeOfString:@"super_img=\""];
NSRange popularURLRange2 = [deviantStringPopular rangeOfString:@"\" super_w"];
int lengt = popularURLRange2.location - popularURLRange1.location -     popularURLRange1.length;
int location = popularURLRange1.location + popularURLRange1.length;
NSRange endRange;
endRange.location = location;
endRange.length = lengt;
popularContent = [deviantStringPopular substringWithRange:endRange];
NSLog(@"%@", popularContent);

The problem is, the other 5 images' URLs are between the same substrings as the first one. So is it possible that the first image's URL is ignored once the it´s loaded successfully and the second one loads and is stored under a different variable and so on?

thanks in advance

DarkThrone
  • 1,954
  • 1
  • 14
  • 14
endFinity
  • 3
  • 1

2 Answers2

0

To get 6 URLs from the string and load them into different variables, you could try using a loop. With each iteration, after the substring is found and stored into a variable, make a range from the beginning of the string up to the end of the substring you found. You can use stringByReplacingCharactersInRange to erase the part of the string already searched so that the next time you search the string for the substring, it will find the next URL.

Tom King
  • 168
  • 5
0

An easier solution may be to use RegexKit, if you know how to use RegEx's. Then each URL could just be a capture group.

wadesworld
  • 13,535
  • 14
  • 60
  • 93
  • Huh, haven´t heard of this yet, I´m pretty new to Objective C. Thanks for the advice, I´ll look into it – endFinity Jul 02 '11 at 08:41