• 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: reading in text files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reading in text files


  • Subject: Re: reading in text files
  • From: Ben Mackin <email@hidden>
  • Date: Thu, 31 Jan 2002 15:36:49 -0800

on 1/31/02 1:18 PM, Ondra Cada at email@hidden wrote:

> I dunno C++, but this looks strange: where you, for example, defined word
> delimiters? But that's unimportant, of course (but that you sould be able to
> do exactly the same exploiting Objective-C++).

I don't define word delimiters. I just set myFile (an fstream) as the input
stream and then read from it. C++ reads one word at a time (from white space
to white space). Meaning if myFile was the following:

Hi a324 is a file to be read

Then the first call to myFile >> string would leave string with 'Hi', and
then the next time I call myFile >> string, string would contain 'a324', and
etc.

I just want to do something like this in Obj-C

> BM> How do I do something like this in Objective-C?
>
> If the delimiter's as simple as a predefined string (like " ") and if the
> file is not tooo big, the simplest way is
>
> NSArray *a=[[NSString stringWithContentsOfFile:theFile]
> componentsSeparatedByString:@" "];
>
> If you need more impressive services, check NSScanner.

myFile is large (can be up to 16000 bytes), so I don't think reading the
whole thing into an NSString would be good.

I thought cocoa/objective-C was to be simple? If somehting is this easy in
C++, it should be a snap in objective-C, right?

Thanks,
Ben


  • Follow-Ups:
    • Re: reading in text files
      • From: Charles Srstka <email@hidden>
References: 
 >Re: <no subject> (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: System contextual menus
  • Next by Date: strange problem with performSelector:
  • Previous by thread: Re: <no subject>
  • Next by thread: Re: reading in text files
  • Index(es):
    • Date
    • Thread