• 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: Greg Titus <email@hidden>
  • Date: Thu, 4 Jul 2002 13:20:18 -0700

Hi Arthur,

The easiest way to do this is code that looks like this:

NSString *file;
NSArray *lines;
NSString *particularLine;

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.

Hope this helps,
-Greg

On Thursday, July 4, 2002, at 08:53 AM, Arthur VIGAN wrote:

OK, thanks. I sorry to ask that stupid question, but I am not yet used to
browse trough the documentation. Sorry.

And what if I just want to keep a particular line of the text/string?
In fact I'm trying to read the state of a process in this text file, so I
know which line to keep.

Arthur


I'm trying to read a text file from my app and transform it into a
NSString*. Do someone see how I can do that?
I found the readRTFDFromFile method for NSText, but my file is a real text
file, not RTF.

See NSString documentation, then (those stringWith... messages).

In case it is non-plain-ASCII, you want to check NSData's dataWith... and
NSString initWith... to be able to specify any string encoding.
_______________________________________________
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.
_______________________________________________
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.

  • Follow-Ups:
    • Re: From text file to NSString...
      • From: Ondra Cada <email@hidden>
References: 
 >Re: From text file to NSString... (From: Arthur VIGAN <email@hidden>)

  • Prev by Date: Re: set/saveFrameUsingName
  • Next by Date: Re: From text file to NSString...
  • Previous by thread: Re: From text file to NSString...
  • Next by thread: Re: From text file to NSString...
  • Index(es):
    • Date
    • Thread