• 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: Cocoa:Reading legacy data files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa:Reading legacy data files


  • Subject: Re: Cocoa:Reading legacy data files
  • From: Timothy Larkin <email@hidden>
  • Date: Sun, 03 Mar 2002 07:52:05 -0500

On 2002.03.03 01:42, "Steven Rogers" <email@hidden> wrote:

> I'm porting an application from Windows =:O and I need to read in a
> structured ASCII file that the program parses with C code.

To solve a similar problem, I defined a document class, which has a method
for - (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)docType.
This is called as a result of the selection of File>Open, and provides the
path to the file in "fileName". The file consists of lines separated by
'\r' and fields separated by '\t'. So

- (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)docType
{
NSArray *lines, *record;
NSString *tab = [NSString stringWithFormat:@"\t"];
NSString *s, *myText;

// Read the entire file into the string 'myText'.
myText = [NSString stringWithContentsOfFile:fileName];

// Parse the data into an array of strings separated by \r.
lines = [myText componentsSeparatedByString:[NSString
stringWithFormat:@"\r"]];

// enumerate the array, line by line
e = [lines objectEnumerator];

// 's' is the current lise
while (s = [e nextObject]) {

// 'record' is an array parsed from 's'.
record = [s componentsSeparatedByString:tab];

// Do something with record here....

}
return YES;
}
_______________________________________________
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.

References: 
 >Reading legacy data files (From: Steven Rogers <email@hidden>)

  • Prev by Date: Drawing into an NSImage?
  • Next by Date: How to identify a menu item?
  • Previous by thread: Reading legacy data files
  • Next by thread: Re: Reading legacy data files
  • Index(es):
    • Date
    • Thread