Re: reading in text files
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