Most memory efficient way to split an NSString in to substrings

前端 未结 2 1893
走了就别回头了
走了就别回头了 2021-01-15 03:29

I have the following code:

    int start = [html rangeOfString:@\"class=WordSection1>\"].location + 24;
    int end = [html rangeOfString:@\"
相关标签:
2条回答
  • 2021-01-15 04:01

    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.

    0 讨论(0)
  • 2021-01-15 04:05

    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.

    0 讨论(0)
提交回复
热议问题