Created
November 4, 2016 07:08
-
-
Save KalpeshTalkar/957e574ec8bbbf42ebb56e892c409576 to your computer and use it in GitHub Desktop.
This is a small function to parse string/data from <html> tags.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by Kalpesh Talkar on 16/12/15. | |
// Copyright © 2015 Kalpesh Talkar. All rights reserved. | |
// | |
/** | |
Function to parse string/data from <html> tags. | |
@param htmlStartTag start tag for e.g. <h1> | |
@param htmlEndTag edn tag for e.g. </h1> | |
@param htmlDocument html file/string containing html code | |
@return string/text/json data in the specified start and end tags if present else nil | |
*/ | |
- (NSString *)getValueForHTMLStartTag:(NSString *)htmlStartTag andHTMLEndTag:(NSString *)htmlEndTag fromDocument:(NSString *)htmlDocument { | |
NSScanner *scanner = [NSScanner scannerWithString:htmlDocument]; | |
NSString *resultString = @""; | |
@try { | |
[scanner scanUpToString:htmlStartTag intoString:nil]; | |
scanner.scanLocation += [htmlStartTag length]; | |
[scanner scanUpToString:htmlEndTag intoString:&resultString]; | |
} | |
@catch (NSException *exception) { | |
return nil; | |
} | |
@finally { | |
return resultString; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment