0

Possible Duplicate:
Find next match of a phrase with NSScanner

I currently have the following code to get a certain piece of code from the UIWebView:

    NSURL *requestTimetableURL = [NSURL URLWithString:@"http://www.dhsb.org/index.phtml?d=201435"];
    NSLog(@"Loaded Timetable");
    NSError *error;
    NSString *page = [NSString stringWithContentsOfURL:requestTimetableURL 
                                              encoding:NSASCIIStringEncoding
                                                 error:&error];

    [webView loadHTMLString:page baseURL:requestTimetableURL];

    NSString* Period1;

    NSScanner *htmlScanner =  [NSScanner scannerWithString:page];

    [htmlScanner scanUpToString:@"<P align=center><STRONG><FONT color=#c00000>" intoString:NULL];
    [htmlScanner scanString:@"<P align=center><STRONG><FONT color=#c00000>" intoString:NULL];
    [htmlScanner scanUpToString:@"</FONT>" intoString:&Period1];

How can I scan a .txt file (which contains the string like above) for the code?

E.G. [htmlScanner scanUpToString:teststring intoString:NULL];

(teststring being the .txt file)

Thanks!

Community
  • 1
  • 1
pixelbitlabs
  • 1,934
  • 6
  • 36
  • 65

1 Answers1

0

NSString *myText = [NSString stringWithContentsOfFile:path];

You can see examples here: http://iphoneincubator.com/blog/data-management/how-to-read-a-file-from-your-application-bundle

if you don't want to read from your bundle (your app) but from your documents dir, use:

NSFileManager* fm = [NSFileManager defaultManager];
NSError* error=nil;
NSURL* docsurl = [fm URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:&error];
NSURL* fileUrl = [docsurl URLByAppendingPathComponent:@"test.txt"];
NSString *myText = [NSString stringWithContentsOfFile:fileUrl.path];
Jan
  • 1,582
  • 1
  • 13
  • 19