응용 프로그램의 CSV 파일에서 읽은 데이터를 정수로 변환해야하는 경우가 있습니다. 나중에 그려야합니다. 현재 데이터를 저장할 때를 인식하지 못합니다.NSArray 구성 요소를 정수 또는 십진수로 변환
int i=[[rows objectAtIndex:0] componentsSeparatedByString:@","];
구현 된 코드입니다.
-(void)connection :(NSURLConnection *) connection didReceiveData:(NSData *)data{
[self serverConnect];
response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//NSLog(response);
NSString *stripped1 = [response stringByReplacingOccurrencesOfString:@"\r" withString:@""];
NSArray *rows = [stripped1 componentsSeparatedByString:@"\n"];
NSArray *components;
for (int i=0;i<[rows count]; i++) {
if(i == 0 || [[rows objectAtIndex:i] isEqualToString:@""]){
continue;
}
components = [[rows objectAtIndex:i] componentsSeparatedByString:@","];
NSLog(@"data1:%@ data2:%@ data3:%@", [components objectAtIndex:0] ,[components objectAtIndex:1],[components objectAtIndex:2]);
}
data1
, data2
및 data3
은 정수로되어있다.
고마워요.