将 URL 转换为 asNSMutableString
以“编辑”该 URL,然后替换该字符串中出现的地标。然后将字符串转回 URL:
NSURL *currentURL = [NSURL URLWithString:@"www.something.com/39.001,29.002;34.0567,-32,0091;56.987,76.435"];
NSMutableString *absolute = [NSMutableString stringWithString:[currentURL absoluteString]];
[absolute replaceOccurrencesOfString:@"34.0567,-32,0091;" withString:@"" options:0 range:NSMakeRange(0, [absolute length])];
NSURL *newURL = [NSURL URLWithString:absolute];
NSLog(@"My new URL = %@", newURL.absoluteString);
编辑---> 更新的代码,包括已更改地标的索引。
NSString *domain = @"www.something.com/";
NSURL *currentURL = [NSURL URLWithString:@"www.something.com/39.001,29.002;34.0567,-32,0091;56.987,76.435"];
NSMutableString *absolute = [NSMutableString stringWithString:[currentURL absoluteString]];
[absolute replaceOccurrencesOfString:domain withString:@"" options:0 range:NSMakeRange(0, [absolute length])];
NSArray *placemarks = [absolute componentsSeparatedByString:@";"];
NSString *placemarkToRemove = @"34.0567,-32,0091";
NSUInteger index = [placemarks indexOfObject:placemarkToRemove];
[absolute replaceOccurrencesOfString:[placemarkToRemove stringByAppendingString:@";"] withString:@"" options:0 range:NSMakeRange(0, [absolute length])];
NSURL *newURL = [NSURL URLWithString:absolute];
NSLog(@"Placemark Index = %u; My new URL = %@", index, newURL.absoluteString);