• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: From text file to NSString...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: From text file to NSString...


  • Subject: Re: From text file to NSString...
  • From: Ondra Cada <email@hidden>
  • Date: Thu, 4 Jul 2002 22:38:09 +0200

On Thursday, July 4, 2002, at 10:20 , Greg Titus wrote:

file = [[NSString alloc] initWithContentsOfFile:myFileName];
lines = [file componentsSeparatedByString:@"\n"];
particularLine = [lines objectAtIndex:lineNumber];
[file release];

Notice though, that this solution reads the whole file, cuts it all up into separate strings for each line, and then takes the one line you are interested in. So this is not efficient if the file you are dealing with is large.

Also, it might cause a leak if eg. lineNumber raises. The proper way to write this is

[[[NSString stringWithContentsOfFile:myFileName] componentsSeparatedByString:@"\n"] objectAtIndex:lineNumber];

(not speaking of the potential problem with encodings, which I've mentioned before).
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >Re: From text file to NSString... (From: Greg Titus <email@hidden>)

  • Prev by Date: Re: From text file to NSString...
  • Next by Date: Re: Drag and Drop
  • Previous by thread: Re: From text file to NSString...
  • Next by thread: How to link with zlib
  • Index(es):
    • Date
    • Thread