我将此 URL 字符串保存为 NSString:
NSString *currentURL = self.webView.request.URL.absoluteString;
https://www.tripresso.com/cooperation/toyota?utm_source=cooperation&utm_medium=toyota&utm_campaign=toyota_app?dxid=7019b21e-bd3b-4bde-8917-f353149bdda4&appid=com.hotai.toyota.citydriver.official
如您所见?
,此字符串中有2个。我的问题是我怎么能代替第二?
用&
?
如果您要删除除第一次出现的所有内容,那么这应该可以工作:
NSString *currentURL = self.webView.request.URL.absoluteString;
NSMutableArray *components = [[currentURL componentsSeparatedByString:@"?"] mutableCopy];
NSString *firstComponent = [components firstObject];
[components removeObject:firstComponent];
NSString *newString = [NSString stringWithFormat:@"%@?%@", firstComponent, [components componentsJoinedByString:@"&"]];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句