URL を「編集」するためにURL を asNSMutableString
に変換し、その文字列内の目印の出現箇所を置き換えます。次に、文字列を 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);