2017-02-23 11 views
0

私はNSStringのとして保存され、このURLの文字列を持っているとそれを置き換える:あなたは2 ?は、この文字列である見ることができるようには、URL文字列に特定の文字を検出し、別の文字

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番目の?を置き換えるにはどうすればいいですか?あなたが最初に出現したが、すべてを削除する場合

答えて

0

、これは動作するはずです:

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:@"&"]]; 
関連する問題