PDA

View Full Version : large array or text file




justmyself
Jan 4, 2009, 03:16 PM
I have a large text file of several hundred lines of text and needed to grab a specified line of text. Would I make an array of with each position holding one line of text, or is there a better approach?

Sorry if this seems so simple but I am new to Objective C and Cocoa. I don't mind taking the time to code the array out, but I have some concerns about the iphone and it's ability to handle an array of such size.

Thanks



drivefast
Jan 4, 2009, 05:25 PM
your definition of the problem is insufficient. a recommendation depends a lot on whether you need to access one single line, one single time per run, or you would have to access several different lines at different points in time, or on whether the lines in the file are in the order you would access them, and so on. try to offer a few more details.

justmyself
Jan 4, 2009, 05:36 PM
your definition of the problem is insufficient. a recommendation depends a lot on whether you need to access one single line, one single time per run, or you would have to access several different lines at different points in time, or on whether the lines in the file are in the order you would access them, and so on. try to offer a few more details.

I only need to access one line of text when the application is launched, and at no other time.

The line number needed would be determined by an int provided by a function. In the array I have coded now is like below

[textToBeDisplayed setStringValue:array[int]];

Additionally the text is static and does not be changed/saved etc...

Hope this helps.

drivefast
Jan 4, 2009, 06:59 PM
then read the lines one by one, counting them, and declare victory when you get to the one you need. internally, reading the file into an array would mean always reading and parsing the whole file, whereas if you read it line by line chances are you need less operations.