나는 세 개의 별도 열에 이름, 성 및 이메일이 포함 된 csv 파일을 업로드 할 수있는 앱을 개발 중입니다. 사용자 인터페이스에는 3 개의 텍스트 필드와 버튼이 있습니다. 사용자가 이름이나 성 또는 전자 메일을 입력하고 검색 버튼을 클릭하면 전체 문서가 검색되어야하며 해당 레코드가 파일에서 발견되었다는 경고를 표시해야합니다. 이것은 사용하고있는 함수이지만 첫 번째 행과 첫 번째 열만 읽습니다.CSV 파일의 개별 필드를 읽고 사용자 입력과 비교하는 방법은 무엇입니까?
- (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;
}
}
}
오 ... 실제로 다른 블록을 시도하지 않고 시도했지만 ... 여전히 첫 번째 행의 첫 번째 열을 확인합니다. – dcprog
무엇입니까? \ [paRowsOfCSVFile count \]와 같습니까? 1이고 파일에 여러 줄이있는 경우 "\ n"대신 "\ r"으로 분할해야합니까? – stevekohls
그래도 작동하지 않습니다 ... 여전히 작동하지 않습니다 – dcprog