Data parsing problem -long
Data parsing problem -long
- Subject: Data parsing problem -long
- From: Bruce Truax <email@hidden>
- Date: Tue, 12 Sep 2006 11:39:10 -0400
- Thread-topic: Data parsing problem -long
Fist I apologize for the length of this post but I would like the opinion of
some more experienced people on this list before I jump into this project.
I have a data reformatting problem to solve and I would like some
suggestions as to the best approach.
To start with I have string and numeric data in an Excel spreadsheet. There
are 137 named columns and about 100 rows. From each row I need to extract
about 30 entries and write them out to a text file in a specific format.
Here is how I would like to approach the problem:
1. Write out the data into a comma separated value or tab delimited text
file.
2. Read the file into an NSDictionary. The first row containing the column
names would define the keys for the dictionary and then the data would be
read into the dictionary as an array under the correct keys.
3. I would have a separate text file listing the names of the keys needed
for my output file. I could read in these keys and use them to access the
appropriate values in the dictionary so that I can write them to my output
file. Using a text file for the list of keys that I want to access allows
me flexibility to change which items are transferred to the output file and
in what order.
I am looking for recommendations how best to read the data from the file and
create the dictionary.
I am assuming that the format of the dictionary is a top level dictionary
containing an array of dictionaries (one for each row of data) as follows:
<dict>
<key>Entry1</key>
<dict>
<key>First Heading</key>
<string>theFirstString</string>
<key>Second Heading</key>
<string>23.4556</ string>
:
:
<key>theLastHeading</key>
<string>23</ string>
</dict>
<key>Entry2</key>
<dict>
<key>First Heading</key>
<string>theSecondString</string>
<key>Second Heading</key>
<string>12.58</ string>
:
:
<key>theLastHeading</key>
<string>11</ string>
</dict>
</dict>
My thought is that I would read the column headers as strings into a c-array
of NSStrings and then read in the values into a second C array of strings.
I could then create the dictionary entry using
initWithObjects:forKeys:count.
In order to add to the top level dictionary as I read the file I assume it
would need to be an NSMutableDictionary and I would add the dictionaries
using setObject:forKey:.
Then to extract the data I would read in the list of keys from the file into
an NSArray. I would then enumerate through the top level entries in the
NSMutableDictionary and use the keys in the NSArray to extract the data and
write it out to a file in the proper order.
Please let me know if I am heading in the right direction.
Thanks.
Bruce
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden