• 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: file parsing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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!


References: 
 >Re: file parsing (From: Chris Gehlker <email@hidden>)

  • Prev by Date: Re: Need Help with Help
  • Next by Date: Re: NSAWTView: please vote
  • Previous by thread: Re: file parsing
  • Next by thread: Re: file parsing
  • Index(es):
    • Date
    • Thread