I have the following code:
int start = [html rangeOfString:@\"class=WordSection1>\"].location + 24;
int end = [html rangeOfString:@\"
Well.. you can't release mainHtml because it is created as an autorelease object, so release will get called after your function is done and it will crash if the object is already released by then.
You could try to create an extra function that splits the string and returns the array, perhaps with an own autorelease pool that you release after the function is run to make sure the strings are released.
Parsing HTML using rangeOfString:
, NSScanner
or regular expressions is futile. It might work for your test case, but it is going to break as soon as the HTML changes.
I.e. keep in mind that:
<div class=\"endofsections\">
And:
<div class=\"endofsections\" id=1
title="End Of Sections" >
Are both identical in terms of the class
attribute.
Use a proper HTML parser.