This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
findme:start [2009/12/20 21:08] syang26 |
findme:start [2009/12/21 15:56] (current) syang26 |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== CVS Parser Final Version Upload (12/20/09) ====== | + | ====== Final Parser Upload (12/20/09) ====== |
- | .h File: | + | Here are the two late uploads of the .h and .m file for the parser. |
- | #import <Foundation/Foundation.h> | + | The last portion of the .m file shows how we store and separate each date and amounts of expenses endowments to different mutable arrays. |
+ | {{:findme:parserimage1.png}} | ||
+ | {{:findme:parserimage2.png}} | ||
+ | {{:findme:parserimage3.png}} | ||
+ | {{:findme:parserimage4.png}} | ||
+ | {{:findme:parserimage5.png}} | ||
- | @interface CVSParser : NSObject { | + | The following are the results printed to NSLog from the parser: |
- | NSInteger maxVal; | + | |
- | NSInteger minVal; | + | |
- | } | + | {{:findme:parserimage6.png}} |
- | -(void)parse; | + | {{:findme:parserimage7.png}} |
- | @end | + | {{:findme:parserimage8.png}} |
- | .m File | ||
- | #import "CVSParser.h" | ||
- | |||
- | @implementation CVSParser | ||
- | -(void)parse{ | ||
- | NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sample-xls-file" ofType:@"csv"]; | ||
- | NSString *contents = [[NSString alloc] initWithContentsOfFile:filePath]; | ||
- | |||
- | NSMutableArray *line = [[NSMutableArray alloc] initWithArray:[contents componentsSeparatedByString:@"\r"]]; | ||
- | NSMutableArray *fullTable = [[NSMutableArray alloc] initWithCapacity:[line count]]; | ||
- | // [[line count]]; | ||
- | |||
- | |||
- | |||
- | for(int i = 0; i < [line count]; i++) { | ||
- | BOOL commaAmmount = FALSE; | ||
- | for(int z = 0; z < [[line objectAtIndex:i] length]; z++) { | ||
- | if([[line objectAtIndex:i] characterAtIndex:z] == '"' && commaAmmount == FALSE) { | ||
- | commaAmmount = TRUE; | ||
- | [line replaceObjectAtIndex:i withObject:[[line objectAtIndex:i] stringByReplacingCharactersInRange:NSMakeRange(z, 1) withString:@""]]; | ||
- | } | ||
- | while(commaAmmount == TRUE && z < [[line objectAtIndex:i] length]) { | ||
- | z++; | ||
- | if([[line objectAtIndex:i] characterAtIndex:z] == '"' && commaAmmount == TRUE) { | ||
- | commaAmmount = FALSE; | ||
- | [line replaceObjectAtIndex:i withObject:[[line objectAtIndex:i] stringByReplacingCharactersInRange:NSMakeRange(z, 1) withString:@""]]; | ||
- | break; | ||
- | } | ||
- | if([[line objectAtIndex:i] characterAtIndex:z] == ',') { | ||
- | [line replaceObjectAtIndex:i withObject:[[line objectAtIndex:i] stringByReplacingCharactersInRange:NSMakeRange(z, 1) withString:@""]]; | ||
- | } | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | |||
- | |||
- | for(int i = 0; i < [line count]; i++) { | ||
- | [fullTable insertObject:[[NSMutableArray alloc]initWithArray:[[line objectAtIndex:i] componentsSeparatedByString:@","]] atIndex:i]; | ||
- | for(int j = 16; j < [[fullTable objectAtIndex:i] count]; j++) { | ||
- | [(NSString *)[[fullTable objectAtIndex:i] objectAtIndex:j] release]; | ||
- | } | ||
- | } | ||
- | int tempFullTableCount = [fullTable count]; | ||
- | for(int i = 0; i < tempFullTableCount; i++) { | ||
- | if([[[fullTable objectAtIndex:i] objectAtIndex:6] isEqualToString:@""] && ![[[fullTable objectAtIndex:i] objectAtIndex:0] isEqualToString:@""]) { | ||
- | NSLog(@"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); | ||
- | [fullTable removeObjectAtIndex:i]; | ||
- | i--; | ||
- | tempFullTableCount--; | ||
- | } | ||
- | } | ||
- | |||
- | int endowmentCount = 0; | ||
- | for(int i = 3; i < [line count]; i++) { | ||
- | if([(NSString *)[line objectAtIndex:i] characterAtIndex:0] == ',' && [(NSString *)[line objectAtIndex:i] characterAtIndex:1] == ',') { | ||
- | break; | ||
- | } | ||
- | endowmentCount++; | ||
- | } | ||
- | int currentBalCount = 0; | ||
- | for(int i = endowmentCount + 3 + 1; i < [line count]; i++) { | ||
- | if([(NSString *)[line objectAtIndex:i] characterAtIndex:0] == ',' && [(NSString *)[line objectAtIndex:i] characterAtIndex:1] == ',') { | ||
- | break; | ||
- | } | ||
- | currentBalCount++; | ||
- | } | ||
- | NSLog(@"currentBalCount : %d", currentBalCount); | ||
- | for(int i = endowmentCount + 3 + currentBalCount + 2; i < [line count]; i++) { | ||
- | if([(NSString *)[line objectAtIndex:i] characterAtIndex:0] == ',' && [(NSString *)[line objectAtIndex:i] characterAtIndex:1] == ',') { | ||
- | break; | ||
- | } | ||
- | currentBalCount++; | ||
- | } | ||
- | int expensesCount = 0; | ||
- | for(int i = endowmentCount + 3 + currentBalCount + 3; i < [line count]; i++) { | ||
- | if([(NSString *)[line objectAtIndex:i] characterAtIndex:0] == ',' && | ||
- | [(NSString *)[line objectAtIndex:i] characterAtIndex:1] == ',' && | ||
- | [(NSString *)[line objectAtIndex:i] characterAtIndex:2] == ',') { | ||
- | break; | ||
- | } | ||
- | expensesCount++; | ||
- | } | ||
- | |||
- | NSArray *category = [[NSArray alloc] initWithArray:[fullTable objectAtIndex:2]]; | ||
- | NSLog(@"category count %d", [category count]); | ||
- | |||
- | for(int i = 0; i < [category count]; i ++) { | ||
- | NSLog(@"category[%d] SUBJECT : %@", i, (NSString *)[category objectAtIndex:i]); | ||
- | } | ||
- | |||
- | |||
- | |||
- | |||
- | NSMutableArray *endowment = [[NSMutableArray alloc] initWithCapacity:endowmentCount]; | ||
- | for(int i = 0; i < endowmentCount; i++) { | ||
- | [endowment insertObject:[fullTable objectAtIndex:i + 2] atIndex:i]; | ||
- | } | ||
- | int tempEndowmentCount = endowmentCount; | ||
- | for(int i = 0; i < tempEndowmentCount; i++) { | ||
- | if([(NSString *)[[endowment objectAtIndex:i] objectAtIndex:6] isEqualToString:@""] || | ||
- | [(NSString *)[[endowment objectAtIndex:i] objectAtIndex:6] isEqualToString:@" "] || | ||
- | [(NSString *)[[endowment objectAtIndex:i] objectAtIndex:6] isEqualToString:@"0.00"]) { | ||
- | NSLog(@"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); | ||
- | [endowment removeObjectAtIndex:i]; | ||
- | i--; | ||
- | tempEndowmentCount--; | ||
- | } | ||
- | } | ||
- | NSMutableArray *currentBal[currentBalCount]; | ||
- | for(int i = 0; i < currentBalCount; i++) { | ||
- | currentBal[i] = [fullTable objectAtIndex:i + endowmentCount + 1 + 2]; | ||
- | } | ||
- | NSMutableArray *expenses = [[NSMutableArray alloc] initWithCapacity:expensesCount]; | ||
- | for(int i = 0; i < expensesCount; i++) { | ||
- | [expenses insertObject:[fullTable objectAtIndex:i + endowmentCount + currentBalCount + 3 + 2] atIndex:i]; | ||
- | } | ||
- | int tempExpensesCount = expensesCount; | ||
- | for(int i = 0; i < tempExpensesCount; i++) { | ||
- | // NSLog(@"Expenses : NULL? %@ , 0.00? %@", [[expenses objectAtIndex:i] objectAtIndex:6], [[expenses objectAtIndex:i] objectAtIndex:6]); | ||
- | if([(NSString *)[[expenses objectAtIndex:i] objectAtIndex:6] isEqualToString:@""] || | ||
- | [(NSString *)[[expenses objectAtIndex:i] objectAtIndex:6] isEqualToString:@" "] || | ||
- | [(NSString *)[[expenses objectAtIndex:i] objectAtIndex:6] isEqualToString:@"0.00"]) { | ||
- | NSLog(@"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); | ||
- | [expenses removeObjectAtIndex:i]; | ||
- | i--; | ||
- | tempExpensesCount--; | ||
- | } | ||
- | } | ||
- | NSLog(@"endowmentCount : %d currentBalCount : %d expensesCount : %d", endowmentCount, currentBalCount, expensesCount); | ||
- | |||
- | NSMutableArray *endowmentDateArray = [[NSMutableArray alloc] initWithCapacity:tempEndowmentCount]; | ||
- | for(int i = 0; i < tempEndowmentCount; i++) { | ||
- | [endowmentDateArray insertObject:[[endowment objectAtIndex:i] objectAtIndex:0] atIndex:i]; | ||
- | NSLog(@"endowment %d Date %@", i, (NSString *)[[endowment objectAtIndex:i] objectAtIndex:0]); | ||
- | } | ||
- | NSMutableArray *expensesDateArray = [[NSMutableArray alloc] initWithCapacity:tempExpensesCount]; | ||
- | for(int i = 0; i < tempExpensesCount; i++) { | ||
- | [expensesDateArray insertObject:[[expenses objectAtIndex:i] objectAtIndex:0] atIndex:i]; | ||
- | NSLog(@"expenses %d Date %@", i, (NSString *)[[expenses objectAtIndex:i] objectAtIndex:0]); | ||
- | } | ||
- | NSMutableArray *endowmentAmountArray = [[NSMutableArray alloc] initWithCapacity:tempEndowmentCount]; | ||
- | for(int i = 0; i < tempEndowmentCount; i++) { | ||
- | [endowmentAmountArray insertObject:[[endowment objectAtIndex:i] objectAtIndex:6] atIndex:i]; | ||
- | NSLog(@"endowment %d Amount %@", i, (NSString *)[[endowment objectAtIndex:i] objectAtIndex:6]); | ||
- | } | ||
- | NSMutableArray *expensesAmountArray = [[NSMutableArray alloc] initWithCapacity:tempExpensesCount]; | ||
- | for(int i = 0; i < tempExpensesCount; i++) { | ||
- | [expensesAmountArray insertObject:[[expenses objectAtIndex:i] objectAtIndex:6] atIndex:i]; | ||
- | NSLog(@"expenses %d Amount %@", i, (NSString *)[[expenses objectAtIndex:i] objectAtIndex:6]); | ||
- | } | ||
- | NSLog(@"////////////////////////////////////////////////////////////////////////////////////////////////////////"); | ||
- | NSLog(@"////////////////////////////////////////////////////////////////////////////////////////////////////////"); | ||
- | NSLog(@"////////////////////////////////////////////////////////////////////////////////////////////////////////"); | ||
- | for(int i = 0; i < [endowmentDateArray count]; i++) { | ||
- | NSLog(@"FINAL ENDOWMENT DATE RESULT : %@", (NSString *)[endowmentDateArray objectAtIndex:i]); | ||
- | } | ||
- | for(int i = 0; i < [endowmentAmountArray count]; i++) { | ||
- | NSLog(@"FINAL ENDOWMENT AMOUNT RESULT : %@", (NSString *)[endowmentAmountArray objectAtIndex:i]); | ||
- | } | ||
- | |||
- | for(int i = 0; i < [expensesDateArray count]; i++) { | ||
- | NSLog(@"FINAL EXPENSES DATE RESULT : %@", (NSString *)[expensesDateArray objectAtIndex:i]); | ||
- | } | ||
- | for(int i = 0; i < [expensesAmountArray count]; i++) { | ||
- | NSLog(@"FINAL EXPENSES AMOUNT RESULT : %@", (NSString *)[expensesAmountArray objectAtIndex:i]); | ||
- | } | ||
- | NSLog(@"LINE COUNT %d, fullTable[0] COUNT %d\n", [line count], [[fullTable objectAtIndex:0] count]); | ||
- | (@"Size of endowmentCount %d", endowmentCount); | ||
- | } | ||
- | @end | ||
- | |||
- | The last part of the .m File shows how we save the arrays of dates and amounts into different muatable arrays. | ||
====== Accessing file (12/10/09) ====== | ====== Accessing file (12/10/09) ====== | ||
We tried to verify the webpage by using Objective-C methods like NSURLCredential, but we failed to access the webpage. | We tried to verify the webpage by using Objective-C methods like NSURLCredential, but we failed to access the webpage. |