Re: file parsing
Re: file parsing
- Subject: Re: file parsing
- From: Nat! <email@hidden>
- Date: Thu, 2 Aug 2001 22:57:14 +0200
Am Donnerstag, 2. August 2001 um 20:10 schrieb Chris Gehlker:
On 8/2/01 8:28 AM, "Mark Wridt" <email@hidden> wrote:
Hello all,
I am new to the list, and to Cocoa(I do have a C++ and
Java background). I am in the process of attempting
to read in a few tab dilimited files, parse them and
then write an ouput file with selected data. Obj-C is
most likely the issue here for me, and I was
wondering if anyone could help (with example code, or
perhaps some URL's)?
This is a simple minded approach for parsing
NSString *s;
NSArray *lines;
NSArray *fields;
unsigned int i, n;
// read complete file into a NSString
s = [NSString stringWithContentsOfFile:@"datafile.txt"];
// separate lines by linefeed into an array of lines
lines = [NSString componentsSeparatedByString:@"\n"];
n = [lines count];
for( i = 0; i < n; i++)
{
// separate each line again by TAB into fields, and output them
fields = [[line objectAtIndex:i] componentsSeparatedByString:@"\t"];
NSLog( @"Parsed fields: %@", fields);
}
I have no idea, how to write the selected data to a file though... :)
Nat!