如何将用户输入与csv文件中的列数据进行比较?

时间:2012-09-27 18:23:09

标签: ios xcode csv

我使用以下代码,但它只检查第一行中的第一列。但我想检查csv文件中所有行的第一列。请帮忙

- (void) SearchStudent 

{ 
    NSArray *DocumentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //I upload the csv file to documents folder of the app through itunes
    NSString *DocumentDirectory = [DocumentPath objectAtIndex:0]; 
    NSString *FullPath = [DocumentDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"example.csv"]]; 
    NSString * pstrCSVFile= [NSString stringWithContentsOfFile:FullPath encoding:NSASCIIStringEncoding error:NULL]; 
    NSArray * paRowsOfCSVFile= [pstrCSVFile componentsSeparatedByString:@"\n"]; 
    NSArray *paColumnsOfRow; 

    NSString *pstrFirstColumn;    
    for(NSString * pstrRow in paRowsOfCSVFile)  
    {  
        paColumnsOfRow= [pstrRow componentsSeparatedByString:@","];  
        pstrFirstColumn= [paColumnsOfRow objectAtIndex:0]; 
        if([pstrFirstColumn localizedCaseInsensitiveCompare:GWIDText.text] == NSOrderedSame) 
        { 
            UIAlertView *alertingFileName = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Found" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];  
            [alertingFileName show]; 
            break; 
        } 
        else 
        { 
            UIAlertView *alertingFileName1 = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Not Found" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
            [alertingFileName1 show]; 
        } 
    }  
} 

1 个答案:

答案 0 :(得分:0)

paColumnsOfRow包含所有行。