0

What I have:

http://hello.com/what?key=value&key1=value1

What I want:

http://hello.com/what

Now I am splitting an NSURL URL by "?" character and get its first part:

[NSURL URLWithString:[request.URL.absoluteString componentsSeparatedByString:@"?"][0]]

Is this a correct solution or there is more practical/correct one?

AndrewShmig
  • 4,843
  • 6
  • 39
  • 68
  • [url query]: http://stackoverflow.com/questions/5903157/ios-parse-a-url-into-segments – stosha Mar 22 '14 at 13:58
  • @Wain, thank you. Should I delete this question or what? – AndrewShmig Mar 22 '14 at 14:28
  • If the other question sorts you out, yes, give it some votes and delete this one :-) – Wain Mar 22 '14 at 14:30
  • 1
    Unfortunately, none of the answers in the linked duplicate is without issues. However, one can rely on the fact, that the first `?` from a valid URI string (from left) separates the query component from the former URI components - if any. Note, that a query *may* have additional questions marks within it. So, the simple and correct solution should be obvious. ;) – CouchDeveloper Mar 22 '14 at 14:54
  • @CouchDeveloper, wow, I really forgot about multiple ? marks... thanks! – AndrewShmig Mar 22 '14 at 17:45

0 Answers0