从CSV文件内容中删除重复的成员并存储在数组中?

时间:2014-10-28 07:58:38

标签: ios iphone xcode ios7

我有一个csv文件有一些重复的成员,我想删除重复和存储数组中的排序值,我使用以下程序,但它不给我独特的数组。 这是我的csv值文件内容

37.46768876,-122.29178052
37.46797307,-122.29193961
37.46825147,-122.29210281
37.46852845,-122.29226818
37.46878976,-122.29244219
37.46905295,-122.29263363
37.46930994,-122.29282659
37.46956224,-122.2930368
37.46980661,-122.29324794
37.47004943,-122.29347317
37.47029083,-122.29370551
37.46768876,-122.29178052
37.46797307,-122.29193961
37.46825147,-122.29210281
37.46852845,-122.29226818
37.46878976,-122.29244219
37.46905295,-122.29263363
37.46930994,-122.29282659
37.46956224,-122.2930368
37.46980661,-122.29324794
37.47004943,-122.29347317
37.47029083,-122.29370551
37.47052113,-122.29393953
37.47074882,-122.29417431
37.47098645,-122.29441454
37.47121917,-122.29465652
37.47146019,-122.2948939
37.47169204,-122.29512775
37.47193243,-122.29536731
37.47216892,-122.29559597
37.4724045,-122.29584441
37.47263575,-122.29607826
37.47287359,-122.29631245
37.47310992,-122.29655586
37.47335094,-122.29678896
37.47358589,-122.2970276
37.47382733,-122.29725927
37.47407652,-122.29748533
37.47432651,-122.29770016
37.47457788,-122.29788741
37.47484795,-122.29807718
37.47511504,-122.29823928
37.46768876,-122.29178052
37.46797307,-122.29193961
37.46825147,-122.29210281
37.46852845,-122.29226818
37.46878976,-122.29244219
37.46905295,-122.29263363
37.46930994,-122.29282659
37.46956224,-122.2930368
37.46980661,-122.29324794
37.47004943,-122.29347317
37.47029083,-122.29370551
37.47052113,-122.29393953
37.47074882,-122.29417431
37.47098645,-122.29441454
37.47121917,-122.29465652
37.47146019,-122.2948939
37.47169204,-122.29512775
37.47193243,-122.29536731
37.47216892,-122.29559597
37.4724045,-122.29584441
37.47263575,-122.29607826
37.47287359,-122.29631245
37.47310992,-122.29655586
37.47335094,-122.29678896
37.47358589,-122.2970276
37.47382733,-122.29725927
37.47407652,-122.29748533
37.47432651,-122.29770016
37.47457788,-122.29788741
37.47484795,-122.29807718
37.47511504,-122.29823928
37.47539512,-122.29839703
37.47567109,-122.29853676
37.47596509,-122.29866961
37.47624844,-122.2987909
37.47654113,-122.29890078
37.47684146,-122.29899726
37.47714065,-122.29908334
37.47744621,-122.29914235
37.47775391,-122.29919189
37.47805503,-122.29923078
37.46768876,-122.29178052
37.46797307,-122.29193961
37.46825147,-122.29210281
37.46852845,-122.29226818
37.46878976,-122.29244219
37.46905295,-122.29263363
37.46930994,-122.29282659
37.46956224,-122.2930368
37.46980661,-122.29324794
37.47004943,-122.29347317
37.47029083,-122.29370551
37.47052113,-122.29393953
37.47074882,-122.29417431
37.47098645,-122.29441454
37.47121917,-122.29465652
37.47146019,-122.2948939
37.47169204,-122.29512775
37.47193243,-122.29536731
37.47216892,-122.29559597
37.4724045,-122.29584441
37.47263575,-122.29607826
37.47287359,-122.29631245
37.47310992,-122.29655586
37.47335094,-122.29678896
37.47358589,-122.2970276
37.47382733,-122.29725927
37.47407652,-122.29748533
37.47432651,-122.29770016
37.47457788,-122.29788741
37.47484795,-122.29807718
37.47511504,-122.29823928
37.47539512,-122.29839703
37.47567109,-122.29853676
37.47596509,-122.29866961
37.47624844,-122.2987909
37.47654113,-122.29890078
37.47684146,-122.29899726
37.47714065,-122.29908334
37.47744621,-122.29914235
37.47775391,-122.29919189
37.47805503,-122.29923078
37.47836852,-122.29925626
37.47867584,-122.29926607
37.47898412,-122.29925944
37.47928265,-122.29924209
37.47959504,-122.29920555
37.47990379,-122.2991675
37.4802021,-122.29911704
37.48050104,-122.29907018
37.48081016,-122.29901151
37.48112252,-122.29896314
37.48143034,-122.2989116
37.48173368,-122.29885946
37.48204679,-122.298808
37.48235759,-122.2987603
37.48267635,-122.29871948
37.48296448,-122.29865444
37.48327373,-122.29860566
37.48356664,-122.29855578
37.48386847,-122.29850608

我的代码......

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, 
YES);
NSString *docDirectory = [paths objectAtIndex:0];

NSString *outputFileName = [docDirectory stringByAppendingPathComponent:@"People.csv"];
NSString* fileContents = [NSString stringWithContentsOfFile:outputFileName encoding:nil error:nil];


NSArray* pointStrings = [fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@"point string=%@",pointStrings);


NSMutableArray* points = [[NSMutableArray alloc] initWithCapacity:pointStrings.count];

for(int idx = 0; idx < pointStrings.count-1; idx++)
{
    // break the string down even further to latitude and longitude fields.
    NSString* currentPointString = [pointStrings objectAtIndex:idx];
    NSArray* latLonArr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];

    CLLocationDegrees latitude  = [[latLonArr objectAtIndex:0] doubleValue];
    CLLocationDegrees longitude = [[latLonArr objectAtIndex:1] doubleValue];

    CLLocation* currentLocation = [[[CLLocation alloc] initWithLatitude:latitude longitude:longitude] autorelease];
    [points addObject:currentLocation];
}



NSMutableArray *pointsunique = [NSMutableArray array];

for (id obj in points) {
    if (![pointsunique containsObject:obj]) {
        [pointsunique addObject:obj];
    }
}
//sortlocationArray = [NSOrderedSet orderedSetWithArray:locationArray];
NSLog(@"pointsunique count %d",[pointsunique count]);//same count,expect less then points count
NSLog(@"temp1 count %d",[points count]);//same count
NSLog(@"pointsunique  %@",pointsunique);

0 个答案:

没有答案