Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6874501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:12:11+00:00 2026-05-27T04:12:11+00:00

I have the following code to read a .txt file and to put it

  • 0

I have the following code to read a .txt file and to put it into a string to use for NSScanner.

    NSString *Period1String = [[NSBundle mainBundle] pathForResource: @"Period1String" ofType: @"txt"];
    NSString *Period2String = [[NSBundle mainBundle] pathForResource: @"Period2String" ofType: @"txt"];
    NSString *Period3String = [[NSBundle mainBundle] pathForResource: @"Period3String" ofType: @"txt"];
    NSString *Period4String = [[NSBundle mainBundle] pathForResource: @"Period4String" ofType: @"txt"];
    NSString *Period5String = [[NSBundle mainBundle] pathForResource: @"Period5String" ofType: @"txt"];

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

    [webView loadHTMLString:page baseURL:requestTimetableURL];

    NSString* Period1;

    NSScanner *htmlScanner =  [NSScanner scannerWithString:page];

    [htmlScanner scanUpToString:Period1String intoString:NULL];
    [htmlScanner scanString:Period1String intoString:NULL];
    [htmlScanner scanUpToString:@"</FONT>" intoString:&Period1];

    period1label.text= Period1;

    NSLog(@"Collected Period 1 Data: %@", Period1);

    NSScanner *htmlScanner2 =  [NSScanner scannerWithString:page];

    NSString* Period2;

    [htmlScanner2 scanUpToString:Period2String intoString:NULL];
    [htmlScanner2 scanString:Period2String intoString:NULL];
    [htmlScanner2 scanUpToString:@"</FONT>" intoString:&Period2];

    period2label.text= Period2;

    NSLog(@"Collected Period 2 Data: %@", Period2);

    NSScanner *htmlScanner3 =  [NSScanner scannerWithString:page];

    NSString* Period3;

    [htmlScanner3 scanUpToString:Period3String intoString:NULL];
    [htmlScanner3 scanString:Period3String intoString:NULL];
    [htmlScanner3 scanUpToString:@"</FONT>" intoString:&Period3];

    period3label.text= Period3;

    NSLog(@"Collected Period 3 Data: %@", Period3);

    NSScanner *htmlScanner4 =  [NSScanner scannerWithString:page];

    NSString* Period4;

    [htmlScanner4 scanUpToString:Period4String intoString:NULL];
    [htmlScanner4 scanString:Period4String intoString:NULL];
    [htmlScanner4 scanUpToString:@"</FONT>" intoString:&Period4];

    period4label.text= Period4;

    NSLog(@"Collected Period 4 Data: %@", Period4);

    NSScanner *htmlScanner5 =  [NSScanner scannerWithString:page];

    NSString* Period5;

    [htmlScanner5 scanUpToString:Period5String intoString:NULL];
    [htmlScanner5 scanString:Period5String intoString:NULL];
    [htmlScanner5 scanUpToString:@"</FONT>" intoString:&Period5];

    period5label.text = Period5;

    NSLog(@"Collected Period 5 Data: %@", Period5);

But, when the button is pressed for all of this to happen, it all the strings (null). Every text file
should be fully working as they have worked for other parts of my app.

Is there a better way I should be doing this or can I improve on this current method to get the results I am looking for?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:12:12+00:00Added an answer on May 27, 2026 at 4:12 am
     NSString *Period1String = [[NSBundle mainBundle] pathForResource: @"Period1String" ofType: @"txt"];
    

    This is setting Period1String to the path to Period1String.txt rather than the contents of Period1String.txt.

    It should be

     NSString *Period1String = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource: @"Period1String" ofType: @"txt"] usedEncoding:nil error:nil];
    

    Substitute in values for encoding and error as appropriate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: <?php $FILE=giant-data-barf.txt; $fp = fopen($FILE,'r'); //read everything into data
When I using the following code to read file: lines=file(data.txt).read().split(\n) I have the following
I have to read a file called hello.txt using the following code on java/eclipse/android:
So I have the following code to check for the text file called Doctors.txt
So I have the following code where I should read a Text File (This
I have the following code: String inputFile = somefile.txt; FileInputStream in = new FileInputStream(inputFile);
I have the following code: (define (get-data) (define port (open-input-file ../data/problem11.txt)) (define field 0)
i have the following file named asmfile.txt copy start 1000 read ldx zero rd
I have the following code with reads a TXT file, pulls out unneeded info
I have the following string in a file called mib.txt: [name=1.3.6.1.2.1.1.5.0, value=myrouter.ad.local (OCTET STRING)]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.