I want to parse a csv file into a table view in Iphone.
I have a csv file with latitude and longtitude and date in the following format.
-37.6704090666667;144.852821866667;2010-07-12 09:34:18
-37.6784624166667;144.867258566667;2010-07-12 09:35:18
-37.6886946666667;144.880478666667;2010-07-12 09:36:18
-37.71000224;144.89458948;2010-07-12 09:37:22
I would like to put the above data in a table where the latitude and the longtitude is in bold separated by a comma and the date below it in smaller lighter font. On clicking this i am taking it into the map with the pointer. I know how to do this but i would like to know how to put the data in the csv file in a table view. And also once i put this data into a table view, i would like to know how to check for invalid coordinates in the entire csv file ?
You can use a wonderful library for CSV Parsing
https://github.com/davedelong/CHCSVParser
Try it. It is simple
For the coordiane validation, you can simply include a checking. The latitude ranges in between -90 to +90. Longitude lies between -180 to +180. Include a simple validation for this
Try this way...
path1 = [[NSString alloc] initWithContentsOfFile:CSVPath encoding:NSUTF8StringEncoding error:&error];
path1=[path1 stringByReplacingOccurrencesOfString:@"\r" withString:@""];
NsArray* messArr=[path1 componentsSeparatedByString:@"\n"];
//MessArr gives the all row from CSV FIle
for(i=1;i<[messArr count]-1;i++)
{
d=[[NSMutableDictionary alloc] init];
StrValue=[NSString stringWithFormat:@"%@",[messArr objectAtIndex:i]];
StrValue=[StrValue stringByReplacingOccurrencesOfString:@"\"" withString:@""];
StrValue=[StrValue stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// Here give whatever saperator you need to saperate data
arr=[StrValue componentsSeparatedByString:@";"];
// This arr gives you the all threee data mean lat,long, & date
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.