-1

I have a url in which I add URL components to it to form a query string. For example the url is https://example.com/test, and with the url components the final url is https://example.com/test?urlcomponent1=1&urlcomponent2=1234.

I need to keep the final url with the urlcomponents, but I need to remove the ?. How do I do that? So the final url would be https://example.com/testurlcomponent1=1&urlcomponent2=1234.

I have looked into removing artifacts, but haven't found a solution.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
jfulton
  • 77
  • 1
  • 10
  • 4
    Curious why you would want to remove the `?` since it makes it an invalid URL. – rmaddy Sep 27 '19 at 17:52
  • For some reason the server I communicate with doesn't like the ?. I know it doesn't make sense, but that is how someone set it up. The ? actually causes an empty response. – jfulton Sep 27 '19 at 18:11
  • 1
    Sounds like there is either an issue with how you call the server or a problem with how the server handles the URL. Which ever it is should be fixed properly. – rmaddy Sep 27 '19 at 18:13

1 Answers1

1

If you know you only have one ? in your url, you can remove it using replacingOccurrencesOf

let newURL = URL(string: url.absoluteString.replacingOccurrences(of: "?", with: ""))
Sean Kladek
  • 4,396
  • 1
  • 23
  • 29
  • 1
    I imagine there would only be one '?'. Can you even have multiple ?s in a valid URL – David Chopin Sep 27 '19 at 18:12
  • I actually did the replacingOccurrences, but put it in the wrong location. This works of course when you add it to the correct url. Thanks. – jfulton Sep 27 '19 at 18:22