here in my code i am trying to load a ROBOTS.TXT file and then filter them by “Disallow” string, then if that line has “Disallow string” delete this string and return the rest of line.
here is a sample of ROBOTS.TXT
User-agent: *
Disallow:/search
Disallow: /groups
Disallow: /images
Disallow: /catalogs
Allow: /catalogs/about
Disallow: /catalogues
Disallow: /news
Allow: /news/directory
and here is the code that i have :
NSRange range;
NSURL *url=[NSURL URLWithString:@"http://www.google.com/robots.txt"];
NSString *content = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSArray *parsed = [content componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
NSMutableArray *robots=[[[NSMutableArray alloc] init] autorelease];
NSMutableString *line= [[[NSMutableString alloc] init] autorelease];
for(line in parsed){
range=[line rangeOfString:@"Disallow"];
if (range.location != NSNotFound) {
[line deleteCharactersInRange: NSMakeRange(1,9 )];
[robots addObject:line];
}
}
and here is the error:
* Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘Attempt to mutate immutable
object with deleteCharactersInRange:’
The variable
lineinfor(line in parsed)is immutable because an NSString is returned by the for-in statement construct.Probably what you need: