我正在构建一个应用程序,用户可以在其中上传一个 csv 文件,其中包含 3 个单独的列中的名字、姓氏和电子邮件。用户界面将有 3 个文本字段和一个按钮。当用户输入名字或姓氏或电子邮件,并单击搜索按钮时,必须搜索整个文档并显示警报,说明在文件中找到了记录。这是我正在使用的函数,但它只读取第一行和第一列。请帮忙
- (void) SearchStudent
{
NSArray *DocumentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
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];
break;
}
}
}