RE: save 2 dimensional array to file
RE: save 2 dimensional array to file
- Subject: RE: save 2 dimensional array to file
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Tue, 3 Jun 2003 13:57:30 -0400
Your data should be an array of arrays or an array of dictionaries. If you
go with two arrays, the "outer" array contains the records, and the "inner"
arrays contain the fields of each record. You can iterate through the outer
array with an enumerator, constructing a new array containing the string
versions of the records using [innerArray componentsJoinedByString:@"\t"].
Once you've done that, you can combine the records in the new outer array
with NSString *writeThis = [newOuterArray componentsJoinedByString:@"\n"].
Then you write writeThis to disk.
If you are starting with an array of dictionaries, iterate over the
dictionaries and put their values into one tab-delimited string per
dictionary. +stringWithFormat is good for this:
[newOuterArray addObject:[NSString stringWithFormat:"%@\t%@", [thisRecord
objectForKey:field1], [thisRecord objectForKey:field2]]];
Then make newOuterArray into a string with componentsJoinedByString. Then
write the string to disk as above.
Hope that helps.
Jonathan
>
-----Original Message-----
>
From: email@hidden
>
[mailto:email@hidden]On Behalf Of Gregor Hofer
>
Sent: Tuesday, June 03, 2003 12:11 PM
>
To: email@hidden
>
Subject: save 2 dimensional array to file
>
>
>
Hi,
>
>
I need to save a 2 dimensional array to a file. The file needs to be
>
imported into excel so the best would be to have a tab delimiter. Does
>
anyone know how to do this?
>
I tried it with NSDictionary and write to File but it saves it into XML
>
format.
>
The output should look something like this:
>
>
1 a b c d ....
>
2
>
3
>
4
>
.
>
.
>
.
>
>
thank you,
>
>
Gregor
>
>
__________________________________________________________________
>
>
Gesendet von Yahoo! Mail - http://mail.yahoo.de
>
Logos und Klingeltvne f|rs Handy bei http://sms.yahoo.de
>
_______________________________________________
>
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.
_______________________________________________
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.