0

Im trying to download HTML in my IOS app, and once i get the html into my app, i want to search the downloaded data and print the text between two values. Example: if i get this data from my html data: content-START the dogs want to do things that do stuff STOP

i want to print the text between START and STOP in a UITextView so people can view the text cleanly. is there any way to do this? Code i have so far:

@implementation FirstViewController


//http://www.streakadvice.com/path-to-the-stash-luke.html
- (void)viewDidLoad{

    [super viewDidLoad];
    if (myConnection == nil) {
        myData = [NSMutableData new];
        NSString *urlString = [NSString stringWithFormat:@"http://www.streakadvice.com/path-to-the-stash-luke.html"];
        myConnection = [NSURLConnection connectionWithRequest:
                       [NSURLRequest requestWithURL:
                        [NSURL URLWithString:urlString]]
                                                    delegate:self];

    }

[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"SFTCBR3.png"]]];


    NSString *fullURL = @"http://www.streakadvice.com/path-to-the-stash-luke.html";
    NSURL *url = [NSURL URLWithString:fullURL];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];



}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [myData appendData:data];
}




-(void)initializeVariablesAgain {
    myData = nil;
    myConnection = nil;
    myTextView = nil;
}




- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

    NSString *stringToLookup = [[NSString alloc]initWithData:myData encoding:NSASCIIStringEncoding];

    if ([stringToLookup rangeOfString:@"Start"].location != NSNotFound) {
        myLabel.text = @" ";
    } else {
        myLabel.text = @" ";
    }

    myTextView.text = [[NSString alloc] initWithData:myData encoding:NSASCIIStringEncoding];

    [self initializeVariablesAgain];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
Gosell1
  • 37
  • 1
  • 9

1 Answers1

0

JSON is probably not the format you are looking for -- especially since it sounds like you just want a basic string replacement. Might I recommend Get String Between Two Other Strings in ObjC ?

Community
  • 1
  • 1
Casey Falk
  • 2,617
  • 1
  • 18
  • 29