我正在开发一个小应用程序,用户通过 iTunes 将 csv 文件上传到应用程序中的文档文件夹。我正在使用以下代码,但它只检查第一行的第一列。它不检查第二行列。我的 csv 文件每个包含 2 行和 4 列。第一列是一个数字。用户将在文本框中键入此号码并单击按钮以检查该号码是否在 csv 文件中。以下功能是我正在使用的功能
-(void)CheckEntry //this function checks the example.csv file
{
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:@"\r\n"];
NSArray *paColumnsOfRow;
NSString *pstrFirstColumn;
for(NSString * pstrRow in paRowsOfCSVFile)
{
paColumnsOfRow= [pstrRow componentsSeparatedByString:@","];
pstrFirstColumn= [paColumnsOfRow objectAtIndex:0];
if([pstrFirstColumn localizedCaseInsensitiveCompare:GWIDText.text] == NSOrderedSame)
{
NSString *msg = [NSString stringWithFormat:@"The record was found"];
UIAlertView *alertingFileName = [[UIAlertView alloc]initWithTitle:msg message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertingFileName show];
}
else
{
NSString *msg = [NSString stringWithFormat:@"Not Found"];
UIAlertView *alertingFileName = [[UIAlertView alloc]initWithTitle:msg message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertingFileName show];
}
}
}