Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Newbie] Basic file handling questions...



If your files are short, you can do the folowing:

NSString *fileText = [[NSString alloc] initWithContentsOfFile:somePath];
NSArray *individualLines = [fileText componentsSeparatedByString:@"\n"];
[fileText release];

// individualLines is now an autoreleased array containing one line at each
index in the array




If your files are long, you can use NSScanner or the technique you are
already using.

You can also always use stdio.

FILE *file = fopen(somePath, "r");

if(NULL != file)
{
char buffer[SOME_LARGE_SIZE];

while(NULL != fgets(buffer, SOME_LARGE_SIZE - 1, file)
{
// do something with the one line of text in buffer
}

fclose(file);
}

----- Original Message -----

References: 
 >[Newbie] Basic file handling questions... (From: Martin-Luc Girard <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.