ユーザーがiTunesを介してアプリのドキュメントフォルダーにcsvファイルをアップロードする小さなアプリを開発しています。次のコードを使用していますが、最初の行の最初の列のみをチェックします。2行目の列をチェックしていません。私の 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];
}
}
}