43 lines
1.3 KiB
Plaintext
43 lines
1.3 KiB
Plaintext
include "NSLog.incl"
|
|
|
|
include resources "rosetta_csv.csv"
|
|
|
|
/*
|
|
|
|
This ASCII text data is saved as a resource file
|
|
named "rosetta_csv.csv" in the application bundle.
|
|
|
|
C1,C2,C3,C4,C5
|
|
1,5,9,13,17
|
|
2,6,10,14,18
|
|
3,7,11,15,19
|
|
4,8,12,16,20
|
|
|
|
*/
|
|
|
|
void local fn ManipulateCSV
|
|
CFURLRef url = fn BundleURLForResource( fn BundleMain, @"rosetta_csv", @"csv", NULL )
|
|
CFStringRef csvString = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
|
|
CFArrayRef csvArray = fn StringComponentsSeparatedByCharactersInSet( csvString, fn CharacterSetNewlineSet )
|
|
CFMutableStringRef mutStr = fn MutableStringWithCapacity(0)
|
|
long i
|
|
|
|
MutableStringAppendFormat( mutStr, @",%@,SUM,AVG\n", csvArray[0] )
|
|
for i = 1 to len(csvArray) - 1
|
|
CFArrayRef nums = fn StringComponentsSeparatedByString( csvArray[i], @"," )
|
|
CFNumberRef sum = fn ObjectValueForKeyPath( nums, @"@sum.self" )
|
|
CFNumberRef avg = fn ObjectValueForKeyPath( nums, @"@avg.self" )
|
|
MutableStringAppendFormat( mutStr, @"R%ld,%@,%@,%@\n",i,csvArray[i],sum,avg )
|
|
next
|
|
|
|
NSLog( @"%@", mutStr )
|
|
|
|
CFURLRef desktopURL = fn FileManagerURLForDirectory( NSDesktopDirectory, NSUserDomainMask )
|
|
url = fn URLByAppendingPathComponent( desktopURL, @"final_csv.csv" )
|
|
fn StringWriteToURL( mutStr, url, YES, NSUTF8StringEncoding, NULL )
|
|
end fn
|
|
|
|
fn ManipulateCSV
|
|
|
|
HandleEvents
|