我有一个URL,在其中添加URL组件以形成查询字符串。例如,URL为https://example.com/test
,使用url组件,最终URL为https://example.com/test?urlcomponent1=1&urlcomponent2=1234
。
我需要使用urlcomponents保留最终的url,但是我需要删除?。我怎么做?因此,最终的网址为https://example.com/testurlcomponent1=1&urlcomponent2=1234
。
我已经研究过去除假象,但是还没有找到解决方法。
答案 0 :(得分:1)
如果您知道只有一个?在您的网址中,您可以使用replaceOccurrencesOf
将其删除let newURL = URL(string: url.absoluteString.replacingOccurrences(of: "?", with: ""))