User Tools

Site Tools


findme:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
findme:start [2009/12/20 21:13]
syang26
findme:start [2009/12/21 15:56] (current)
syang26
Line 1: Line 1:
 ====== Final Parser Upload (12/20/09) ====== ====== Final Parser Upload (12/20/09) ======
 Here are the two late uploads of the .h and .m file for the parser. Here are the two late uploads of the .h and .m file for the parser.
-The last portion of the .m file shows how we store and seperate ​each date and amounts of expenses endowments to different mutable arrays. +The last portion of the .m file shows how we store and separate ​each date and amounts of expenses endowments to different mutable arrays.
-''#​import "​CVSParser.h"​+
  
-@implementation CVSParser +{{:findme:parserimage1.png}
--(void)parse{ +{{:findme:parserimage2.png}
- NSString *filePath = [[NSBundle mainBundle] pathForResource:​@"​sample-xls-file"​ ofType:​@"​csv"​];​ +{{:findme:parserimage3.png}} 
- NSString *contents = [[NSString alloc] initWithContentsOfFile:​filePath];​ +{{:findme:parserimage4.png}} 
-  +{{:findme:parserimage5.png}}
- 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; +The following are the results printed to NSLog from the parser:
- 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]]; +{{:findme:parserimage6.png}} 
- NSLog(@"​category count       ​%d",​ [category count]);+{{:​findme:​parserimage7.png}} 
 +{{:​findme:​parserimage8.png}}
  
- 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 
-''​ 
 ====== 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.
findme/start.1261365214.txt.gz · Last modified: 2009/12/20 21:13 by syang26