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 8491865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:33:19+00:00 2026-06-10T22:33:19+00:00

I have a textfile which consists of multiple words. They are all separated by

  • 0

I have a textfile which consists of multiple words. They are all separated by new lines.

What Ive tried:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"txt"];

if (filePath) { // This does trigger, so the file is actually found.

    NSArray *arr = [filePath componentsSeparatedByString:@"\n"]; 

}

What Ive also tried:

NSMutableArray * lines = [[NSMutableArray alloc] initWithArray:[filePath componentsSeparatedByString:@"\n"] copyItems: YES];

Neither of these seems to work as I only seem to get the filepath when I read out lines using NSLog. Can any of you help?

The lines array only seem to consist of one object, the string of the location of the textfile.

I want an array where each string is a string separated by a line in the textile.

  • 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-06-10T22:33:21+00:00Added an answer on June 10, 2026 at 10:33 pm

    First of all you need to get the file within your application bundle. That means, you must put it inside your application’s ‘Resources’ folder.

    Then you can read it like this:

    NSString* path = [[NSBundle mainBundle] pathForResource:@"filename" 
                                                     ofType:@"txt"];
    

    Then loading the content into a NSString is even easier:

    NSString* content = [NSString stringWithContentsOfFile:path
                                                  encoding:NSUTF8StringEncoding
                                                     error:NULL];
    

    Then create the array:

    NSArray *arr = [content componentsSeparatedByString:@"\n"]; //might also be @"\r" check both.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textfile in which some words are printed in ALL CAPS. I
I have a text file which consists of different lines it looks like Destination|203.190.242.69|reached|203.190.244.6
I have a text file (tab separated) which consist of 17 column. I would
I have a large textfile, which has linebreaks at column 80 due to console
I have some data which I run through, which generates a textfile. The data
I have a text file which needs to be constantly updated (regular intervals). All
I have a textfile which my Java program is modifying and putting into an
I have a list box that reads from a textfile to which the user
I have a parameter file which is a textfile - bug.par, which several parameters
I am new to VC++ and programming. I have a task in which I

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.